- Creating a Git branch
- Writing the Deployment manifest
- Understanding each field in the YAML
- Next steps for automated deployment
Prerequisites
- A working GKE cluster
kubectlconfigured to talk to your GKE cluster- Docker image pushed to a container registry (e.g., Google Container Registry)
1. Create a New Git Branch
Open your terminal, ensure you’re onmain, then create a feature branch:
Make sure you have committed or stashed any local changes before switching branches.
2. Define the Deployment Manifest
In the root of your project, create a file namedGKE.yaml. This manifest tells Kubernetes how many replicas to run, which Docker image to use, and which port to expose.
3. Manifest Field Reference
Below is a quick reference for the key fields inGKE.yaml:
| Field | Description | Example |
|---|---|---|
| apiVersion | Kubernetes API version for the Deployment resource | apps/v1 |
| kind | Resource type | Deployment |
| metadata.name | Unique name for your Deployment | gcp-devops-gke |
| spec.replicas | Number of pod replicas to maintain | 1 |
| spec.selector.matchLabels | Label selector matching pods managed by this Deployment | app: gcp |
| spec.template.metadata.labels | Labels applied to each pod | app: gcp |
| spec.template.spec.containers | Container definitions including image, ports, and env variables | name, image URL, containerPort: 5000, env PORT=5000 |
4. Verify and Apply the Manifest
OnceGKE.yaml is saved, apply it to your GKE cluster:
Always review your manifest for correct image tags and port configurations before applying to production clusters.
5. Next Steps
Now that your Deployment manifest is live, update your CI/CD pipeline to automate this step. For example, extend yourcloudbuild.yaml to:
- Build and push the Docker image
- Run
kubectl apply -f GKE.yamlagainst your GKE cluster
main automatically deploys the latest version.