Quickstart: Deploy to Cloud Run on GKE

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

  1. 登入您的 Google 帳戶。

    如果您沒有帳戶,請申請新帳戶

  2. 選取或建立 Google Cloud Platform 專案。

    前往「Manage resources」(管理資源) 頁面

  3. 請確認您已啟用 Google Cloud Platform 專案的計費功能。

    瞭解如何啟用計費功能

  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 on GKE:

  1. Install and initialize the 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 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 \
      --cluster-version=latest \
      --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 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 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 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:

  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 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:

  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:

本頁內容對您是否有任何幫助?請提供意見:

傳送您對下列選項的寶貴意見...

這個網頁
Cloud Run