kustomize edit set image command into your CI/CD pipeline. By the end, you’ll understand how to automatically update your Kubernetes manifests with a new image tag whenever a build completes successfully.
Table of Contents
- CI/CD Pipeline Overview
- 1. Triggering the Pipeline
- 2. Installing Dependencies & Running Tests
- 3. Building & Tagging the Container Image
- 4. Updating Manifests with
kustomize edit - 5. Deploying to Kubernetes
- References
CI/CD Pipeline Overview
This is a typical flow for deploying code changes:| Stage | Description | Example Command |
|---|---|---|
| Push Code | Developer pushes to GitHub | git push origin main |
| Build | Install deps & run tests | go mod download / go test ./... |
| Tag & Push | Build Docker image with commit hash, push to registry | docker build -t myrepo/api:$GIT_COMMIT_HASH .docker push myrepo/api:$GIT_COMMIT_HASH |
| Update | Use Kustomize to set the new image in manifests | kustomize edit set image api=myrepo/api:$GIT_COMMIT_HASH |
| Deploy | Apply the updated overlay to production cluster | kubectl apply -k overlays/production |
Using a Git commit hash (or semantic version) as your Docker image tag ensures traceability between your code and the container you deploy.
1. Triggering the Pipeline
Any push to the main branch starts the CI/CD process. For example:2. Installing Dependencies & Running Tests
In the build stage, install dependencies and execute tests:3. Building & Tagging the Container Image
Most CI systems provide an environment variable for the commit SHA. For instance:myrepo/api:abcdef123 uniquely identifies the image corresponding to this commit.
4. Updating Manifests with kustomize edit
In the CD stage, adjust your Kustomize overlay so the manifest points to the new image tag:images section of your kustomization.yaml:
Ensure your
kustomization.yaml is under version control so you can track these automated updates. Avoid committing sensitive credentials or hardcoded tags.5. Deploying to Kubernetes
With your overlay updated, deploy the change to production:myrepo/api:abcdef123, and perform a rolling update.