Setting up Cloud Run on GKE

This guide shows how to set up a Google Kubernetes Engine cluster with Cloud Run on GKE enabled. Because you can use either the GCP Console or the gcloud command line, the instructions cover both of these.

Note that enabling Cloud Run on GKE 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. Select or create a GCP project.

    Go to the Project selector page

  3. Make sure that billing is enabled for your Google Cloud Platform project.

    Learn how to enable billing

Setting up gcloud

Although you can use either the GCP Console console or the gcloud command line to use Cloud Run on GKE, you must use the gcloud command line for certain tasks, such as setting up outbound networking.

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

  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 gcloud beta components:

    gcloud components install beta
  7. 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 on GKE enabled
  • Kubernetes version: see recommended versions
  • Nodes with 4 vCPU
  • Scopes to access cloud-platform, write to logging, write to monitoring

These are the minimum settings.

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 on GKE:

  1. Go to the Google Kubernetes Engine page in the GCP 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:

    standard cluster template

    • Enter the name you want for your cluster.
    • Choose either Zonal or regional for the location type: either will work with Cloud Run on GKE. 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, or use us-central1-a.
    • From the dropdown list, select one of the recommended versions as the Master custer version.
    • Configure the node pool with these recommended settings:

      • Set Number of nodes to 3
      • For Machine type select 4 vCPUs.
    • In the Node pool form, click More node pool options to expand the form.

      • These instructions don't enable cluster autoscaling, so leave the checkbox Enable autoscaling unchecked. Note that even if you don't enable autoscaling of the cluster size, Cloud Run on GKE will always autoscale instances of your services within the cluster.

      • Under Security, change the Access scopes to Allow full access to all Cloud APIs:

        cluster security

      • Click Save.

    • Click Availability, networking, security, and additional features to expand the form, and scroll down to Stackdriver:

      Stackdriver features

      • Select Enable Stackdriver Logging service.
      • Select Enable Stackdriver Montoring service
      • Select Try the new Stackdriver beta Monitoring and Logging experience
      • Select the Enable Istio (beta) checkbox.
      • Set Enable mTLS to Permissive.
      • Select the checkbox Enable Cloud Run on GKE (beta)

      Note that you must select Stackdriver Monitoring and Logging in order to create the cluster.

  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 on GKE:

  1. Create a new cluster using the command:

    gcloud beta container clusters create CLUSTER_NAME \
    --addons=HorizontalPodAutoscaling,HttpLoadBalancing,Istio,CloudRun \
    --machine-type=n1-standard-4 \
    --cluster-version=latest --zone=ZONE \
    --enable-stackdriver-kubernetes --enable-ip-alias \
    --scopes cloud-platform

    Replace

    • CLUSTER_NAME with the name you want for your cluster.
    • ZONE with the zone you are using for your cluster, for example, us-central1-a. You can use any zone supported by GKE. Note that the cluster won't be created unless you use the parameter --enable-stackdriver-kubernetes as shown.

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

  2. Wait for the cluster creation to complete.

  3. Set gcloud defaults to use your new cluster and cluster location, to avoid having to specify these when you use the gcloud command line:

    gcloud config set run/cluster CLUSTER_NAME
    gcloud config set run/cluster_location us-central1-a

    Replace CLUSTER_NAME with the name you used for your cluster, and if necessary replace us-central1-a with the supported cluster location of your choice.

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 CLUSTER_LOCATION
    gcloud container clusters get-credentials CLUSTER

    Replace CLUSTER and CLUSTER_LOCATION with the name and location of the cluster you are using.

  2. Optionally, create a new cluster namespace. Kubernetes clusters come with a namespace named default. If you need 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

Outbound network access and Istio sidecar injection

Outbound network access is now enabled by default starting with GKE cluster version 1.12.7-gke.17 (for 1.12-based clusters) and 1.11.9-gke.13 (for 1.11-based clusters).

Users of previous cluster versions can find the instructions for manually enabling at Enabling outbound network access.

Additionally, also starting with the above cluster versions, Istio sidecar injection is no longer enabled by default. To enable this, refer to the Istio sidecar documentation.

Setting up a custom domain

If you want to use custom domains, see Mapping custom domains.

Disabling Cloud Run on GKE

During the beta, Cloud Run on GKE cannot be disabled after you create a cluster with it enabled. You must delete the cluster to stop the Cloud Run on GKE components from running. Note that this permanently deletes workloads in the cluster and all other cluster states.

You can use the console UI or the gcloud command line to delete clusters: select the tab for instructions.

Console

To delete the cluster:

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

    Go to Google Kubernetes Engine

  2. Select the cluster you want to delete.

  3. Click Delete.

Command line

To delete a cluster:

  1. Invoke the following command:

    gcloud beta container clusters delete CLUSTER_NAME

    Replace CLUSTER_NAME with the name of the cluster you are deleting.

  2. When prompted to confirm the cluster deletion, respond y.

  3. Wait for the deletion to finish. You should see messages similar to the following:

      Deleting cluster my-cluster...done.
      Deleted [https://container.googleapis.com/v1beta1/projects/my-project-1234/zones/us-central1-b/clusters/serverless-cluster].

What's next

Оцените, насколько информация на этой странице была вам полезна:

Оставить отзыв о...

Текущей странице
Cloud Run Documentation