Streamlining Application Deployment with Google Cloud Deploy
Introduction
In today’s fast-paced digital landscape, the ability to swiftly and seamlessly deploy applications is a key factor in staying competitive. Google Cloud Deploy, a cutting-edge continuous delivery tool, offers a comprehensive solution to simplify and optimize application deployment to various Google Cloud services, including Google Kubernetes Engine (GKE), Anthos, and Cloud Run. In this blog post, we’ll delve deeply into the specifics of deploying applications to GKE clusters using Helm Charts, and how the potent combination of Google Cloud Deploy and Skaffold can revolutionize and supercharge your deployment pipeline.
The Power of Google Cloud Deploy
Google Cloud Deploy is a game-changer in the world of application deployment. It is built upon Skaffold, an open-source tool developed by Google. What sets Skaffold apart is its adaptability and versatility. It provides robust support for a range of deployment tools, including Helm, kpt, and raw manifest files. This adaptability ensures that you have the freedom to choose the deployment method that best aligns with your project’s specific requirements.
A Closer Look at Deployment Pipelines
One of the standout features of Google Cloud Deploy is its innate capacity to define multiple target environments. This, in turn, allows for a seamless transition of applications from one environment to another. This journey can encompass various stages such as development, staging, testing, and, ultimately, production.
To set up a delivery pipeline for your cloud deployment, a YAML file can be harnessed. This YAML file serves as the blueprint for your deployment pipeline, encapsulating all the vital information necessary for the application’s progression through various environments. Below is an example of a delivery pipeline definition in YAML:
apiVersion: deploy.cloud.google.com/v1
kind: DeliveryPipeline
metadata:
name: test-pipeline #Name of the delivery pipeline
description: deploy pipeline for testing cloud deploy
serialPipeline: #Defines to progess it as a serial pipeline
stages:
- targetId: stage
profiles: [stage] #Skaffold profile to deploy to the target
- targetId: dev
profiles: [dev]
- targetId: qa
profiles: [qa]
- targetId: prod
profiles: [prod]
This YAML file lays down a structured pathway for your deployment, guiding it through the stages from development to production, ensuring a smooth and efficient deployment process.
Tailoring Target Environments
Each target environment in your deployment pipeline is defined in YAML, specifying the GKE cluster, execution configurations, and any unique requirements.
---
# Multiple Target definition
apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
name: stage
description: stage cluster
# Cluster endpoint
gke:
cluster: projects/example-stage/locations/us-west1/clusters/stage-primary
executionConfigs:
- usages:
- RENDER
- DEPLOY
# workload identity service account
defaultPool:
serviceAccount: example-stage-sa@example-stage.iam.gserviceaccount.com
---
apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
name: dev
description: dev cluster
gke:
cluster: projects/example-stage/locations/us-west1/clusters/dev-primary
executionConfigs:
- usages:
- RENDER
- DEPLOY
defaultPool:
serviceAccount: example-stage-sa@example-stage.iam.gserviceaccount.com
---
apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
name: qa
description: qa cluster
gke:
cluster: projects/example-stage/locations/us-west1/clusters/qa-primary
executionConfigs:
- usages:
- RENDER
- DEPLOY
defaultPool:
serviceAccount: example-stage-sa@example-stage.iam.gserviceaccount.com
Ensuring Safety in Production
When deploying applications to production, safety is paramount. Google Cloud Deploy offers a valuable feature — the ability to require manual approval before proceeding with production deployments. This adds an additional layer of security, ensuring that critical deployments undergo rigorous review before going live.
---
apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
name: prod
description: prod cluster
gke:
cluster: projects/example-stage/locations/us-west1/clusters/prod-primary
requireApproval: True # Manual Approval
executionConfigs:
- usages:
- RENDER
- DEPLOY
defaultPool:
serviceAccount: example-stage-sa@example-stage.iam.gserviceaccount.com
Creating Your Deployment Pipeline
With your target environments carefully defined, you can create the Cloud Deploy pipeline using the following command:
gcloud deploy apply --file=clouddeploy.yaml --region=us-central1 --project=ops-primary
Crafting Skaffold Configurations
Now that your deployment pipeline is in place, it’s time to create the Skaffold configuration. This configuration acts as the rulebook for how your application is deployed to each target environment. Here’s an example of a Skaffold configuration for the ‘stage’ environment:
apiVersion: skaffold/v4beta6
kind: Config
profiles:
- name: stage # skaffold profiles
deploy:
helm:
releases:
- name: redis-test
chartPath: .
valuesFiles: # values file in order of overrides
- values/global.yaml
- values/redis-test/stage.yaml
namespace: stage
useHelmSecrets: true #Users the helm secrets plugin
- name: dev
deploy:
helm:
releases:
- name: redis-test
chartPath: .
valuesFiles:
- values/global.yaml
- values/redis-test/dev.yaml
namespace: dev
useHelmSecrets: true
- name: qa
deploy:
helm:
releases:
- name: redis-test
chartPath: .
valuesFiles:
- values/global.yaml
- values/redis-test/qa.yaml
namespace: qa
useHelmSecrets: true
- name: prod
deploy:
helm:
releases:
- name: redis-test
chartPath: .
valuesFiles:
- values/global.yaml
- values/redis-test/preprod.yaml
namespace: preprod
useHelmSecrets: true
Creating Releases with Confidence
Once your Skaffold configuration is in place, you can create releases to deploy your application to the target environments defined in your deployment pipeline. For instance, to deploy the ‘redis-test’ application to the first target environment in the pipeline, you can use the following command:
gcloud deploy releases create redis-test-$RANDOM \
--project=ops-primary \
--region=us-central1 \
--delivery-pipeline=test-pipeline \
--skaffold-file skaffold.yaml
After setting up the pipeline and configuring skaffold, applying them to the cloud deploy pipeline enables the seamless promotion of application changes across various environments. This allows you to monitor deployment metrics, including the frequency and rate of deployment for your application.
To promote the release across different environments, follow these steps: first, click on the “Promote” option specific to the targeted cluster. Next, select the release that you intend to deploy and execute the necessary changes. Before implementing the deployment, take advantage of the option to thoroughly examine the detailed modifications that are set to be applied to the targeted environment. This careful review ensures a comprehensive understanding of the changes before they are finalised and deployed.
Conclusion
In conclusion, Google Cloud Deploy, combined with Skaffold, offers a robust and flexible solution for deploying applications to GKE clusters. By defining deployment pipelines, customising target environments, and harnessing Skaffold configurations, you can streamline and automate your deployment process while ensuring manual approvals in critical stages. This approach guarantees that your applications are delivered reliably and efficiently across a spectrum of environments. So, why wait? It’s time to harness these formidable tools to elevate your application deployment workflow with Google Cloud Deploy today. Your applications deserve nothing less than the best, and Google Cloud Deploy ensures just that.