This page shows you how to create a cluster enabled for Cloud Run on GKE and then deploy a prebuilt sample container to the cluster.
You can also follow this quickstart with a demo account on Qwiklabs.
Before you begin
-
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.
- Install cURL if you want to send a request to the deployed sample service.
- Set up the gcloud command line, described next.
Setting up gcloud
To set up the gcloud command line for Cloud Run on GKE:
Set the platform to
gkeand set your default project setting forgcloudto the one you just created:gcloud config set run/platform gke gcloud config set project PROJECT-ID
Replace PROJECT-ID with the project ID of the project you created.
Set 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
Creating a GKE cluster with Cloud Run enabled
To create a cluster and enable it for 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 --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-kubernetesas 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.
Wait for the cluster creation to complete. During the creation process, you should see messages similar to the following:
Creating cluster my-cluster...done. Created [https://container.googleapis.com/v1beta1/ \ projects/my-project/zones/us-central1-b/clusters/my-cluster].where
my-projectis your own project ID. You have just created a new Google Kubernetes Engine cluster namedmy-clusterin the projectmy-projectSet 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.
Deploying a sample container
To deploy a container to the cluster you just created:
Click Create service to display the Create service form. In the form,
Use the sample
gcr.io/cloudrun/helloas the container image.Use the name hello as the service name. You use can some other name, but if you do, make sure you use that name later when you use the CURL command to access the service. These instructions assume you use hello.
In the Location dropdown, make sure you select the cluster you just created in the previous steps.
Click Create and wait for the deployment to finish. This creates the service and deploys it to Cloud Run on GKE.
Congratulations! You have just deployed a service to a Cloud Run on GKE enabled cluster.
Accessing your deployed service
After you deploy your service, you can use CURL to send a request and verify the service is working, using the external IP address of the Load Balancer service created for the Istio ingress controller:
Go to the Google Kubernetes Engine page in the GCP Console:
Click Services in the left navigation panel to display a list of services.
Scroll down to the
istio-ingressgatewayservice and copy the external IP address shown next to the Load Balancer, WITHOUT THE PORT setting, if there is one. For example, if the IP isXX.XXX.XX.XXX:15020, omit the:15020. Ignore the other IP addresses listed.Invoke CURL, making sure to replace hello in the
Hoststring with the name of your service, if you used a service name other than hello:curl -v -H "Host: hello.default.example.com" YOUR-IP
Replace YOUR-IP with the IP address you obtained in the previous step.
Clean up
Disabling Cloud Run on GKE
During the beta, Cloud Run on GKE cannot be disabled after installation. You must delete the cluster if you wish to stop the Cloud Run on GKE components from running. Note that this will permanently delete workloads in the cluster and all other cluster state.
To delete the cluster:
Go to the Google Kubernetes Engine page in the GCP Console:
Select the cluster you want to delete.
Click Delete.
What's next
To learn how to build a container from code source, push to Container Registry, and deploy, see:


