Skip to main content
In this guide, you’ll learn how to integrate the 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

  1. CI/CD Pipeline Overview
  2. 1. Triggering the Pipeline
  3. 2. Installing Dependencies & Running Tests
  4. 3. Building & Tagging the Container Image
  5. 4. Updating Manifests with kustomize edit
  6. 5. Deploying to Kubernetes
  7. References

CI/CD Pipeline Overview

This is a typical flow for deploying code changes:
StageDescriptionExample Command
Push CodeDeveloper pushes to GitHubgit push origin main
BuildInstall deps & run testsgo mod download / go test ./...
Tag & PushBuild Docker image with commit hash, push to registrydocker build -t myrepo/api:$GIT_COMMIT_HASH .
docker push myrepo/api:$GIT_COMMIT_HASH
UpdateUse Kustomize to set the new image in manifestskustomize edit set image api=myrepo/api:$GIT_COMMIT_HASH
DeployApply the updated overlay to production clusterkubectl 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:
git push origin main
Your CI system (GitHub Actions, Jenkins, GitLab CI, etc.) detects the new commit and enters the build stage.

2. Installing Dependencies & Running Tests

In the build stage, install dependencies and execute tests:
# Download Go modules
go mod download

# Execute all tests
go test ./...
If all tests pass, the pipeline moves on to building the Docker image.

3. Building & Tagging the Container Image

Most CI systems provide an environment variable for the commit SHA. For instance:
# Provided by CI environment
GIT_COMMIT_HASH=abcdef123

# Build and tag the image
docker build -t myrepo/api:$GIT_COMMIT_HASH .
docker push myrepo/api:$GIT_COMMIT_HASH
Here, 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:
kustomize edit set image api=myrepo/api:$GIT_COMMIT_HASH
This command modifies the images section of your kustomization.yaml:
images:
- name: api
  newName: myrepo/api
  newTag: abcdef123
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:
kubectl apply -k overlays/production
Kubernetes will detect the new image tag, pull myrepo/api:abcdef123, and perform a rolling update.

References