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.
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
Select or create a GCP project.
Make sure that billing is enabled for your Google Cloud Platform project.
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:
You should set your default project setting for
gcloudto the one you just created:
gcloud config set project PROJECT-ID
Replace PROJECT-ID with the project ID of the project you created.
zoneto 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.
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
Update installed gcloud components:
gcloud components update
Install the gcloud beta components:
gcloud components install beta
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.
To create a cluster and enable it for Cloud Run on GKE:
Go to the Google Kubernetes Engine page in the GCP Console:
Click Create cluster to open the Create a Kubernetes cluster page.
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 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
- 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:
Click Availability, networking, security, and additional features to expand the form, and scroll down to Stackdriver:
- 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.
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.
To create a new cluster that enables Cloud Run on GKE:
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 \ --scopes cloud-platform
- 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
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.
Wait for the cluster creation to complete.
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-awith the supported cluster location of your choice.
Configuring gcloud for cluster and platform
After you create the cluster,
- Set your default platform to
- 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:
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.
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.
If you created a new namespace in the previous step, and want to use it rather than the
defaultnamespace, 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
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.
To delete the cluster:
Go to the Google Kubernetes Engine page in the GCP Console:
Select the cluster you want to delete.
To delete a cluster:
Invoke the following command:
gcloud beta container clusters delete CLUSTER_NAME
Replace CLUSTER_NAME with the name of the cluster you are deleting.
When prompted to confirm the cluster deletion, respond
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].