Deploying your Docker image to Google Kubernetes Engine (GKE) can be fully automated using Cloud Build. In this guide, we’ll update our CI/CD pipeline by extendingDocumentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
cloudbuild.yaml to:
- Build the Docker image
- Push it to Google Container Registry (GCR)
- Deploy to a GKE cluster with a Kubernetes manifest
Prerequisites
- A GKE cluster up and running
gcloudCLI configured with your project and zone- Cloud Build API enabled
- Service account with the following roles:
roles/container.developerroles/storage.admin
Ensure your Cloud Build service account has the Kubernetes Engine Developer and Storage Admin roles. Without these, build or deploy steps may fail.
Kubernetes Deployment Manifest
We’ve already created a Kubernetes Deployment manifest (gke.yaml) for our sample app:
Initial cloudbuild.yaml
Our startingcloudbuild.yaml only built and pushed the Docker image:
Extending cloudbuild.yaml for GKE Deployment
We’ll add a third step to invoke thegke-deploy builder, which applies our Kubernetes manifest directly to GKE:
Step-by-Step Overview
| Step | Builder Image | Arguments | Purpose |
|---|---|---|---|
| 1 | gcr.io/cloud-builders/docker | build -t gcr.io/$PROJECT_ID/gcpdevops . | Build the container image |
| 2 | gcr.io/cloud-builders/docker | push gcr.io/$PROJECT_ID/gcpdevops | Push image to Google Container Registry |
| 3 | gcr.io/cloud-builders/gke-deploy | run --filename=gke.yaml --image=gcr.io/$PROJECT_ID/gcpdevops --location=us-central1-c --cluster=gke-gcp-devops --namespace=gcp-devops-prod | Deploy manifest to your GKE cluster |
References
Next Steps
- Commit and push your updated
cloudbuild.yamlto a feature branch. - Open a pull request for review.
- Merge into
main.