Deploy an app to multiple targets at the same time
This page shows you how to use Cloud Deploy to deliver a sample application to two targets at the same time—a parallel deployment.
In this quickstart, you'll do the following:
Create two GKE clusters or two Cloud Run services.
You can deploy in parallel to GKE attached clusters too, but this quickstart uses GKE and Cloud Run only.
Create a Skaffold configuration and either a Kubernetes manifest or a Cloud Run service definition.
Define your Cloud Deploy delivery pipeline and deployment targets.
This pipeline will have only one target, but that target will be a multi-target—a target that represents more than one deployment target. This multi-target will comprise two actual targets, delivering your app to the two clusters or services.
Instantiate your delivery pipeline by creating a release, which automatically deploys to the two targets in parallel.
View the "controller rollout" and child rollouts in Google Cloud console.
Before you begin
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Deploy, Cloud Build, GKE, Cloud Run, and Cloud Storage APIs, if any are not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init - 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.
- First add the
clouddeploy.jobRunnerrole:gcloud projects add-iam-policy-binding PROJECT_ID \ --member=serviceAccount:$(gcloud projects describe PROJECT_ID \ --format="value(projectNumber)")-compute@ \ --role="roles/clouddeploy.jobRunner" - Add the developer role for your specific runtime.
- For GKE:
gcloud projects add-iam-policy-binding PROJECT_ID \ --member=serviceAccount:$(gcloud projects describe PROJECT_ID \ --format="value(projectNumber)")-compute@ \ --role="roles/container.developer" - For Cloud Run:
gcloud projects add-iam-policy-binding PROJECT_ID \ --member=serviceAccount:$(gcloud projects describe PROJECT_ID \ --format="value(projectNumber)")-compute@ \ --role="roles/run.developer" -
Add the
iam.serviceAccountUserrole, which includes theactAspermission to deploy to the runtime:gcloud iam service-accounts add-iam-policy-binding $(gcloud projects describe PROJECT_ID \ --format="value(projectNumber)")-compute@ \ --member=serviceAccount:$(gcloud projects describe PROJECT_ID \ --format="value(projectNumber)")-compute@ \ --role="roles/iam.serviceAccountUser" \ --project=PROJECT_ID
- First add the
If you already have the CLI installed, make sure you're running the latest version:
gcloud components update
Create your runtime environments
If you're deploying to Cloud Run, you can skip this command.
For GKE, create two clusters: quickstart-cluster-qsprod1
and quickstart-cluster-qsprod2, with default settings. The
clusters' Kubernetes API endpoints must be network-reachable from the public
internet. GKE clusters are externally accessible by
default.
gcloud container clusters create-auto quickstart-cluster-qsprod1 \
--project=PROJECT_ID \
--region=us-central1 \
&& gcloud container clusters create-auto quickstart-cluster-qsprod2 \
--project=PROJECT_ID \
--region=us-west1
Prepare your Skaffold configuration and application manifest
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
application manifest to be used to deploy the sample app.
Open a terminal window.
Create a new directory and navigate into it.
GKE
mkdir deploy-gke-parallel-quickstart cd deploy-gke-parallel-quickstartCloud Run
mkdir deploy-run-parallel-quickstart cd deploy-run-parallel-quickstartCreate a file named
skaffold.yamlwith the following contents:GKE
apiVersion: skaffold/v4beta1 kind: Config manifests: rawYaml: - k8s-deployment.yaml deploy: kubectl: {}Cloud Run
apiVersion: skaffold/v4beta1 kind: Config manifests: rawYaml: - service.yaml deploy: cloudrun: {}This file is a minimal Skaffold config. For this quickstart, you create the file. But you can also have Cloud Deploy create one for you, for simple, non-production applications.
See the
skaffold.yamlreference for more information about this file.Create the definition for your application—a service definition for Cloud Run or a Kubernetes manifest for GKE.
GKE
Create a file named
k8s-deployment.yaml, with the following contents:apiVersion: apps/v1 kind: Deployment metadata: name: