Setting up Cloud Run for Anthos on Google Cloud

This guide shows how to set up a new Google Kubernetes Engine cluster with Cloud Run for Anthos on Google Cloud enabled. Because you can use either the Cloud Console or the gcloud command line, the instructions cover both of these. If you are enabling Cloud Run on an already existing cluster, refer to Enabling Cloud Run for Anthos on Google Cloud on existing clusters

Note that enabling Cloud Run for Anthos on Google Cloud installs Istio and Knative Serving into the cluster to connect and manage your stateless workloads.

Prerequisites

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Cloud Console, on the project selector page, select or create a Cloud project.

    Go to the project selector page

  3. Verifica che la fatturazione sia attivata per il tuo progetto.

    scopri come attivare la fatturazione

Setting up gcloud

Although you can use either the Cloud Console console or the gcloud command line to use Cloud Run for Anthos on Google Cloud, you may need to use the gcloud command line for some tasks.

To set up the gcloud command line for Cloud Run for Anthos on Google Cloud:

  1. Install and initialize the Cloud SDK.

  2. You should set your default project setting for gcloud to the one you just created:

    gcloud config set project PROJECT-ID

    Replace PROJECT-ID with the project ID of the project you created.

  3. Set zone to the desired zone for the new cluster. You can use any zone where GKE is supported, for example:

    gcloud config set compute/zone ZONE

    Replace ZONE with your zone.

  4. Enable the following APIs for the project, which are needed to create a cluster, build and publish a container into the Google Container registry:

    gcloud services enable container.googleapis.com containerregistry.googleapis.com cloudbuild.googleapis.com
  5. Update installed gcloud components:

    gcloud components update
  6. Install the kubectl command-line tool:

    gcloud components install kubectl

Creating a cluster with Cloud Run enabled

These instructions create a cluster with this configuration:

  • Cloud Run for Anthos on Google Cloud enabled
  • Kubernetes version: see Available GKE versions
  • Nodes with 2 vCPU

These are the recommended settings for a new cluster.

You can use either the gcloud command line or the console to create a cluster. Click the appropriate tab for instructions.

Console

To create a cluster and enable it for Cloud Run for Anthos on Google Cloud:

  1. Go to the Google Kubernetes Engine page in the Cloud Console:

    Go to Google Kubernetes Engine

  2. Click Create cluster to open the Create a Kubernetes cluster page.

  3. Select the Standard cluster template, and set the following values in the template:

    • Enter the name you want for your cluster.
    • Choose either Zonal or regional for the location type: either will work with Cloud Run for Anthos on Google Cloud. Zonal clusters are less expensive, but will incur downtime during master upgrades.
    • Select a zone or region for the cluster, depending on your choice in the previous step. Choose a zone or region close to you, for example, us-central1-a.
    • From the dropdown list, select one of the available versions as the Master cluster version.

    • Select the checkbox Enable Cloud Run for Anthos.

  4. Click Create to create and provision the cluster with the configuration you just completed. It may take a few moments for this process to finish.

Command line

To create a new cluster that enables Cloud Run for Anthos on Google Cloud:

  1. Create a new cluster:

    • For GKE versions 1.15.3-gke.19 and greater, 1.14.3-gke.12 and greater, 1.13.10-gke.8 and greater, use

      gcloud beta container clusters create CLUSTER_NAME \
      --addons=HorizontalPodAutoscaling,HttpLoadBalancing,CloudRun \
      --machine-type=n1-standard-2 \
      --num-nodes=3 \
      --cluster-version=GKE_VERSION
      --enable-stackdriver-kubernetes 
    • For older GKE versions, use

      gcloud beta container clusters create CLUSTER_NAME \
      --addons=HorizontalPodAutoscaling,HttpLoadBalancing,Istio,CloudRun \
      --machine-type=n1-standard-2 \
      --num-nodes=3 \
      --cluster-version=GKE_VERSION
      --enable-stackdriver-kubernetes

    Replace

    • CLUSTER_NAME with the name you want for your cluster.
    • GKE_VERSION with the desired GKE version. See available versions.

    Note that although these instructions don't enable cluster autoscaling to resize clusters for demand, Cloud Run for Anthos on Google Cloud automatically scales instances within the cluster.

  2. Wait for the cluster creation to complete.

Configuring gcloud for cluster and platform

After you create the cluster,

  • Set your default platform to gke.
  • Optionally set defaults for cluster name, and cluster location to avoid subsequent prompts for these when you use the command line.
  • Get credentials that allow the gcloud command line to access your cluster.

To set defaults:

  1. Set the default platform to gke, set your default cluster and cluster location, and then get credentials as follows:

    gcloud config set run/platform gke
    gcloud config set run/cluster CLUSTER
    gcloud config set run/cluster_location ZONE
    gcloud container clusters get-credentials CLUSTER

    Replace

    • CLUSTER with the name of the cluster
    • ZONE with the location of the cluster.
  2. Kubernetes clusters come with a namespace named default. For information on namespaces, and why you might want to create and use a namespace other than default, refer to namespace in the Kubernetes documentation. To create a new namespace, run:

    kubectl create namespace NAMESPACE

    Replace NAMESPACE with the Namespace you want to create.

  3. If you created a new namespace in the previous step, and want to use it rather than the default namespace, set that new namespace as the one to be used by default when you invoke the gcloud command line:

    gcloud config set run/namespace NAMESPACE

Setting up a custom domain

If you want to use custom domains that apply to the cluster, refer to Using a custom domain. For per-service custom domains, refer to Mapping custom domains.

Disabling Cloud Run for Anthos on Google Cloud

To disable Cloud Run for Anthos on Google Cloud in your cluster:

  1. Go to the Google Kubernetes Engine page in the Cloud Console:

    Go to Google Kubernetes Engine

  2. Click the cluster where you want to disable Cloud Run for Anthos on Google Cloud .

  3. Click Edit.

  4. From the Cloud Run for Anthos dropdown, select Disable.

  5. Click Save.

What's next

Hai trovato utile questa pagina? Facci sapere cosa ne pensi:

Invia feedback per...

Cloud Run Documentation