Quickstart: Deploy to Cloud Run for Anthos on Google Cloud

This page shows you how to create a cluster enabled for Cloud Run for Anthos on Google Cloud and then deploy a prebuilt sample container to that cluster.

If you have a demo account, you can instead follow this quickstart 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. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

  4. To ensure you have the latest version of the Cloud SDK, either install or update the Cloud SDK:

Setting up the command-line environment and enabling the required APIs

Complete the following steps to set up your command-line environment for Cloud Run for Anthos and enable the required APIs:

  1. Configure the gcloud command-line tool to use the ID of your Cloud project by default:

    gcloud config set project PROJECT-ID

    Replace PROJECT-ID with your project's ID.

  2. Set the platform to gke:

    gcloud config set run/platform gke
  3. Set the zone where you want the new cluster to be deployed. You can use any zone where GKE is supported. For example:

    gcloud config set compute/zone ZONE

    Replace ZONE with your desired zone.

  4. Run the gcloud services command to enable the following APIs in your Cloud project:

    • Google Kubernetes Engine API: Create GKE clusters.
    • Cloud Build API: Build containers.
    • Container Registry API: Publish containers to Container Registry.
    gcloud services enable container.googleapis.com containerregistry.googleapis.com cloudbuild.googleapis.com

Creating a GKE cluster with Cloud Run for Anthos enabled

Complete the following steps to create a cluster and enable it for Cloud Run for Anthos:

  1. Create a new cluster using the command:

    gcloud container clusters create CLUSTER_NAME \
      --addons=HttpLoadBalancing,CloudRun \
      --machine-type=n1-standard-2 \
      --enable-stackdriver-kubernetes

    Replace CLUSTER_NAME with the name you want for your 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 the ID of your Cloud project and my-cluster is the cluster that you just created.

  3. Set the gcloud defaults for your Cloud Run for Anthos resources to the name of your new cluster and its location. You set these defaults to avoid specifying these values each time that you use the gcloud command-line tool.

    gcloud config set run/cluster CLUSTER_NAME
    gcloud config set run/cluster_location ZONE

    Replace CLUSTER_NAME and ZONE with the same values that you used to create your new cluster.

Deploying a sample container

Use the Google Cloud Console to deploy a sample container and create a service in your cluster:

  1. In the Cloud Console, go to the Cloud Run for Anthos page.

    Go to Cloud Run for Anthos

  2. Open the Create service form by clicking Create service:

    1. Select Cloud Run for Anthos as your development platform.

    2. In the available clusters dropdown menu, select the cluster you just created.

    3. Leave default entered as the name of the namespace.

    4. Enter a service name, such as hello.

    5. Click Next.

    6. Select Deploy one revision from an existing container image, then select hello from the demo containers drop-down.

    7. Click Next.

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

    9. Click Create to deploy the image to Cloud Run for Anthos and wait for the deployment to finish.

Congratulations! You have just deployed a service to a Cloud Run for Anthos enabled cluster.

Accessing your deployed service

Now that you have a service running, you can to send requests to it. In this section, cURL is used to demonstrate how to access your service and verify that it's working:

  1. In the Cloud Console, go to the Cloud Run for Anthos page.

    Go to Cloud Run for Anthos

  2. Click the name of your new Cloud Run for Anthos service to go to its Service details page.

  3. Click info , located to the right of the service's URL.

  4. Click Invoke in Cloud Shell to run the generated cURL command for your service in Cloud Shell.

The cURL request returns the source code of the sample container that your service is running. Now you've verified that your service is handling requests!

Clean up

You can either disable Cloud Run for Anthos, or you can delete the cluster and the Cloud Run for Anthos service to avoid incurring costs for running these resources.

Disabling Cloud Run for Anthos

To disable Cloud Run for Anthos and keep your cluster:

  1. In the Cloud Console, go to the Google Kubernetes Engine page.

    Go to Google Kubernetes Engine

  2. Click the cluster where you want to disable Cloud Run for Anthos.

  3. Click Edit.

  4. Scroll down to Anthos Features and from the Cloud Run for Anthos dropdown, select Disable.

  5. Click Save.

Deleting Cloud Run for Anthos

To permanently delete your GKE cluster, including the Cloud Run for Anthos service and all its resources:

  1. In the Cloud Console, go to the Google Kubernetes Engine page.

    Go to Google Kubernetes Engine

  2. Select the cluster you want to delete.

  3. Click Delete, the click Delete again on the pop up.

What's next

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

For an architectural overview of Cloud Run for Anthos that covers the changes from installing Cloud Run for Anthos as an add-on to your Google Kubernetes Engine cluster, see: