Quickstart: Deploy to Cloud Run for Anthos
Learn to create a cluster enabled for Cloud Run for Anthos and then deploy a prebuilt sample container to that cluster.
If you have a demo account, you can instead follow this quickstart on Google Cloud Skills Boost.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project. Learn how to check if billing is enabled on a project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project. Learn how to check if billing is enabled on a project.
- To ensure you have the latest version of the Google Cloud CLI, either install or update the Google Cloud CLI:
- Install and initialize the Google Cloud CLI.
- If you've already installed the gcloud CLI, update the installed
components:
gcloud components update
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:
Configure the Google Cloud CLI to use the ID of your Google Cloud project by default:
gcloud config set project PROJECT-ID
Replace PROJECT-ID with your project's ID.
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.
Run the
gcloud services
command to enable the following APIs in your Google 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
This might take several seconds to complete. When the APIs have been enabled, the command line displays a message similar to the following:
Operation "operations/..." finished successfully.
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:
Create a new cluster using the command:
gcloud container clusters create CLUSTER_NAME \ --addons=HttpLoadBalancing,CloudRun \ --machine-type=e2-standard-4 \ --num-nodes=4 \ --enable-stackdriver-kubernetes
Replace CLUSTER_NAME with the name you want for your 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-project
is the ID of your Google Cloud project andmy-cluster
is the cluster that you just created.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 Google Cloud CLI.gcloud config set run/platform gke 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:
In the Google Cloud console, go to the Cloud Run for Anthos page.
Open the Create service form by clicking Create service.
In the available clusters dropdown menu, select the cluster you just created.
Leave
default
entered as the name of the namespace.Enter a service name, such as
hello
.Click Next.
Select Deploy one revision from an existing container image, then select
hello
from the demo containers drop-down.Click Next.
Select External under Connectivity, so that you can invoke the service.
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:
In the Google Cloud console, go to the Cloud Run for Anthos page.
Click the name of your new Cloud Run for Anthos service to go to its Service details page.
Click info
, located to the right of the service's URL.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:
In the Google Cloud console, go to the Google Kubernetes Engine page.
Click the cluster where you want to disable Cloud Run for Anthos.
Click Edit.
Scroll down to Anthos Features and from the Cloud Run for Anthos dropdown, select Disable.
Click Save.
Deleting Cloud Run for Anthos
To permanently delete your GKE cluster, including the Cloud Run for Anthos service and all its resources:
In the Google Cloud console, go to the Google Kubernetes Engine page.
Select the cluster you want to delete.
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: