Cloud Run is a managed compute platform that enables you to run stateless containers that are invocable via HTTP requests. Cloud Run is serverless: it abstracts away all infrastructure management, so you can focus on what matters most — building great applications.
Cloud Run is built from Knative, letting you choose to run your containers either fully managed with Cloud Run, or in your Google Kubernetes Engine cluster with Cloud Run on GKE.
The goal of this codelab is for you to setup Cloud Run on a GKE cluster and deploy a container as a service.
If you see a "request account button" at the top of the main Codelabs window, click it to obtain a temporary account. Otherwise ask one of the staff for a coupon with username/password.
These temporary accounts have existing projects that are set up with billing so that there are no costs associated for you with running this codelab.
Note that all these accounts will be disabled soon after the codelab is over.
Use these credentials to log into the machine or to open a new Google Cloud Console window https://console.cloud.google.com/. Accept the new account Terms of Service and any updates to Terms of Service.
Here's what you should see once logged in:
When presented with this console landing page, please select the only project available. Alternatively, from the console home page, click on "Select a Project" :
While Google Cloud can be operated remotely from your laptop, in this codelab we will be using Google Cloud Shell, a command line environment running in the Cloud.
This Debian-based virtual machine is loaded with all the development tools you'll need. It offers a persistent 5GB home directory, and runs on the Google Cloud, greatly enhancing network performance and authentication. This means that all you will need for this codelab is a browser (yes, it works on a Chromebook).
To activate Google Cloud Shell, from the developer console simply click the button on the top right-hand side (it should only take a few moments to provision and connect to the environment):
Then accept the terms of service and click the "Start Cloud Shell" link:
Once connected to the cloud shell, you should see that you are already authenticated and that the project is already set to your
gcloud auth list
Credentialed accounts: - <myaccount>@<mydomain>.com (active)
gcloud config list project
[core] project = <PROJECT_ID>
If for some reason the project is not set, simply issue the following command :
gcloud config set project <PROJECT_ID>
Looking for your
PROJECT_ID? Check out what ID you used in the setup steps or look it up in the console dashboard:
IMPORTANT: Finally, set the default zone and project configuration:
gcloud config set compute/zone us-central1-f
You can choose a variety of different zones. Learn more in the Regions & Zones documentation.
Using your browser, navigate to the Google Kubernetes Engine (GKE) section in Google Cloud Console: console.cloud.google.com/kubernetes
Click Create cluster to open the Create a Kubernetes cluster page, select the Standard cluster template, and set the following values in the template:
Still in the Node pool section, click More options :
Back in the "'Standard cluster' template", click "Availability, networking, security, and additional features" to expand the form, and scroll down to Stackdriver:
Finally click Create to create and provision the GKE cluster
Creating the Cloud Run-enabled cluster will take a few moments. Please wait for the cluster to be ready before moving to the next step.
To deploy a container to the cluster you have just created, go to the Cloud Run section (console.cloud.google.com/run) and click Create service :
gcr.io/cloudrun/helloas the sample container image
Congratulations, you have just created the service and deployed it to Cloud Run on GKE :
Note the URL listed on the top. This will be needed to test the deployed service in the next and final step.
Once you've deployed your service, you can use
curl to send a request and verify the service is working, using the cluster's IP address.
To avoid having to setup DNS, we'll test the deployed service by sending a request to the Istio ingress gateway (Knative is built using Istio) with the target host that should handle the request sent as an HTTP header. That hostname should be the URL listed in the previous deployment step and of the form:
From Cloud Console, go back to the GKE section (console.cloud.google.com/kubernetes) and click Services in the left navigation panel to display the list of services.
Scroll down to the
istio-ingressgateway service and copy the IP address shown next to the load balancer. Ignore the other values under that IP address.
From Cloud Shell, use
curl to access the service :
curl -v -H "Host: hello-run-gke.default.example.com" http://[INGRESS-GATEWAY-IP]
[INGRESS-GATEWAY-IP] with the IP address you obtained in the previous step, and if you used a service name other than "
hello-run-gke" you'll need to replace that as well.
The response should be
HTTP 200 along with the default "
Congratulations | Cloud Run" HTML content :
* Rebuilt URL to: http://188.8.131.52:80/ * Trying 184.108.40.206... * TCP_NODELAY set * Connected to 220.127.116.11 (18.104.22.168) port 80 (#0) > GET / HTTP/1.1 > Host: hello-run-gke.default.example.com > User-Agent: curl/7.52.1 > Accept: */* > < HTTP/1.1 200 OK < content-type: text/html; charset=utf-8 <...> <title>Congratulations | Cloud Run</title>