Quickstart: Deploy to Cloud Run for Anthos deployed on GKE

This page shows you how to create a cluster enabled for Cloud Run for Anthos deployed 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

  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.

  4. Install cURL if you want to send a request to the deployed sample service.
  5. Set up the gcloud command line, described next.

Setting up gcloud

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

  1. Install and initialize Cloud SDK.

  2. Set the platform to gke and set your default project setting for gcloud to 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.

  3. 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.

  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

Creating a GKE cluster with Cloud Run enabled

To create a cluster and enable it for Cloud Run for Anthos deployed 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 \
      --zone=ZONE \
      --enable-stackdriver-kubernetes \
      --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 for Anthos deployed on GKE automatically scales instances within the cluster.

  2. 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-project is your own project ID. You have just created a new Google Kubernetes Engine cluster named my-cluster in the project my-project

  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.

Deploying a sample container

To deploy a container to the cluster you just created:

  1. Go to Cloud Run

  2. Click Create service to display the Create service form. In the form,

    1. Use the sample gcr.io/cloudrun/hello as the container image.

    2. Select Cloud Run for Anthos deployed on GKE as your development platform.

    3. 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.

    4. In the available clusters dropdown menu, select the cluster you just created in the previous steps.

    5. Select External under Connectivity, so you can invoke the service.

  3. Click Create and wait for the deployment to finish. This creates the service and deploys it to Cloud Run for Anthos deployed on GKE.

Congratulations! You have just deployed a service to a Cloud Run for Anthos deployed 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:

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

    Go to Google Kubernetes Engine

  2. Click Services in the left navigation panel to display a list of services.

  3. Scroll down to the istio-ingressgateway service 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 is XX.XXX.XX.XXX:15020, omit the :15020. Ignore the other IP addresses listed.

  4. Invoke cURL, making sure to replace hello in the Host string 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 for Anthos deployed on GKE

During the beta, Cloud Run for Anthos deployed on GKE cannot be disabled after installation. You must delete the cluster if you wish to stop the Cloud Run for Anthos deployed on GKE components from running. Note that this will permanently delete workloads in the cluster and all other cluster state.

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.

What's next

To learn how to build a container from code source, push to Container Registry, and deploy, see:

Was this page helpful? Let us know how we did:

Send feedback about...