Quickstart: deploy an application

This page shows you how to use Google Cloud Deploy to deliver a sample application image named echoserver to a sequence of two Google Kubernetes Engine clusters.

In this quickstart, you'll do the following:

  1. Create the two clusters.

  2. Create a Skaffold configuration and a Kubernetes manifest to specify the (pre-built) container image to deploy.

  3. Define your Google Cloud Deploy delivery pipeline, including deployment targets, which point to the two clusters.

  4. Instantiate your delivery pipeline by creating a release, which automatically deploys to the first target.

  5. Promote the release to the second target.

  6. View both rollouts in Cloud Console.

Before you begin

  1. 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.
  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

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

  4. Enable the Google Cloud Deploy, Cloud Build, GKE, and Cloud Storage APIs.

    Enable the APIs

  5. Install and initialize the Cloud SDK.
  6. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

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

  8. Enable the Google Cloud Deploy, Cloud Build, GKE, and Cloud Storage APIs.

    Enable the APIs

  9. Install and initialize the Cloud SDK.
  10. Make sure the default Compute Engine service account has sufficient permissions.

    The service account might already have the necessary permissions. These steps are included for projects that disable automatic role grants for default service accounts.

    1. Add the clouddeploy.jobRunner role:

      gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=serviceAccount:$(gcloud projects describe PROJECT_ID \
          --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
          --role="roles/clouddeploy.jobRunner"
      

    2. Add the Kubernetes developer permissions:

      gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=serviceAccount:$(gcloud projects describe PROJECT_ID \
          --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
          --role="roles/container.developer"
      

      If you have trouble adding either of these roles, contact your project administrator.

Create your Google Kubernetes Engine clusters

Create two clusters: qsdev and qsprod, with default settings. The clusters' Kubernetes API endpoints must be network-reachable from the public internet. GKE clusters are externally accessible by default.

  1. Create the qsdev cluster:

    gcloud container clusters create quickstart-cluster-qsdev --project=PROJECT_ID --region=us-central1
    
  2. Create the qsprod cluster:

    gcloud container clusters create quickstart-cluster-qsprod --project=PROJECT_ID --region=us-central1
    

Prepare your Skaffold configuration and Kubernetes manifest

Google Cloud Deploy uses Skaffold to provide the details for what to deploy and how to deploy it properly for your separate targets.

In this quickstart, you create a skaffold.yaml file, which identifies the Kubernetes manifest to be used to deploy the sample app.

  1. Open a terminal window.

  2. Create a new directory, named deploy-quickstart and navigate into it.

    mkdir deploy-quickstart
    cd deploy-quickstart
    
  3. Create a file named skaffold.yaml with the following contents:

    apiVersion: skaffold/v2beta16
    kind: Config
    deploy:
      kubectl:
        manifests:
          - k8s-*
    
  4. Create a file named k8s-pod.yaml, with the following contents:

    apiVersion: v1
    kind: Pod
    metadata:
      name: getting-started
    spec:
      containers:
      - name: echoserver
        image: my-app-image
    

Create your delivery pipeline and targets

You can define your pipeline and targets in one file or in separate files. In this quickstart, you create a single file.

  1. In the deploy-quickstart directory, create a new file: clouddeploy.yaml, with the following contents:

    apiVersion: deploy.cloud.google.com/v1beta1
    kind: DeliveryPipeline
    metadata:
     name: my-demo-app-1
    description: main application pipeline
    serialPipeline:
     stages:
     - targetId: qsdev
       profiles: []
     - targetId: qsprod
       profiles: []
    ---
    
    apiVersion: deploy.cloud.google.com/v1beta1
    kind: Target
    metadata:
     name: qsdev
    description: development cluster
    gke:
     cluster: projects/PROJECT_ID/locations/us-central1/clusters/quickstart-cluster-qsdev
    ---
    
    apiVersion: deploy.cloud.google.com/v1beta1
    kind: Target
    metadata:
     name: qsprod
    description: production cluster
    gke:
     cluster: projects/PROJECT_ID/locations/us-central1/clusters/quickstart-cluster-qsprod
    
  2. Register your pipeline with the Google Cloud Deploy service:

    gcloud beta deploy apply --file clouddeploy.yaml --region=us-central1 --project=PROJECT_ID
    

    You now have a pipeline, with targets, ready to deploy your application to your first target.

  3. Confirm your pipeline and targets:

    In the Cloud Console, navigate to the Google Cloud Deploy Delivery pipelines page to view of list of your available delivery pipelines.

    Open the Delivery pipelines page

    The delivery pipeline you just created is shown, and the two targets are listed in the Targets column.

    delivery pipeline visualization in Google Cloud Console

Create a release

A release is the central Google Cloud Deploy resource representing the changes being deployed. The delivery pipeline defines the lifecycle of that release. See Google Cloud Deploy service architecture for details about that lifecycle.

Run the following command from the deploy-quickstart directory to create a release resource that represents the container image to deploy:

gcloud beta deploy releases create test-release-001 \
  --project=PROJECT_ID \
  --region=us-central1 \
  --delivery-pipeline=my-demo-app-1 \
  --images=my-app-image=k8s.gcr.io/echoserver:1.4

Because this release is the first one (being deploying into the first target in the progression), Google Cloud Deploy automatically creates a rollout resource too. The application is automatically deployed into the first target in the progression.

Promote the release

  1. From the Delivery pipelines page, click the my-demo-app-1 pipeline.

    Open the Delivery pipelines page

    The Delivery pipeline details page shows a graphical representation of your delivery pipeline's progress. In this case, it shows that the release was deployed to the qsdev target.

    delivery pipeline visualization in Google Cloud Console

  2. On the first target in the delivery pipeline visualization, click Promote.

    The Promote release dialog is shown. It shows the details of the target you're promoting to.

  3. Click Promote.

    The release is now queued for deployment into qsprod. When deployment is complete, the delivery pipeline visualization shows it as deployed:

    delivery pipeline visualization in Google Cloud Console

View the results in Cloud Console

  1. In the Cloud Console, navigate to the Google Cloud Deploy Delivery pipelines page to view your my-demo-app-1 delivery pipeline.

    Open the Delivery pipelines page

  2. Click the name of your deliver pipeline "my-demo-app-1".

    The pipeline visualization shows the app's progress through the pipeline.

    delivery pipeline visualization in Google Cloud Console

    And your release is listed on the Releases tab under Delivery pipeline details.

  3. Click the release name, test-release-001.

    Your rollouts appear under Rollouts. You can click a rollout to view its details, including the deployment log.

    rollouts in Google Cloud Console

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

  1. Delete the qsdev cluster:

    gcloud container clusters delete quickstart-cluster-qsdev --region=us-central1 --project=PROJECT_ID
    
  2. Delete the qsprod cluster:

    gcloud container clusters delete quickstart-cluster-qsprod --region=us-central1 --project=PROJECT_ID
    
  3. Delete the delivery pipeline:

    gcloud beta deploy delivery-pipelines delete my-demo-app-1 --force --region=us-central1 --project=PROJECT_ID
    

    This command deletes the delivery pipeline itself, plus all release and rollout resources Google Cloud Deploy created for that pipeline.

  4. Delete the Cloud Storage buckets that Google Cloud Deploy created.

    One ends with _clouddeploy, and the other is [region].deploy-artifacts.[project].appspot.com.

    Open the Cloud Storage browser page

That's it, you completed this quickstart!

What's next