- a Deployment manifest (original),
- Kustomize
images:transformations (inkustomization.yaml), - the resulting rendered manifests after running
kustomize buildorkubectl kustomize.
Initial Deployment (deployment.yaml)
Example 1 — Replace the image name (newName)
kustomization snippet that replaces the base image namenginx with haproxy:
newName transform:
Note: The
name field under images: in kustomization.yaml matches the image reference (for example nginx), not the container name in the Pod/Deployment spec. The container’s name: web is independent and does not affect Kustomize image matching.Example 2 — Change only the tag (newTag)
If you want to keep the same image name but change the tag:newTag transform:
Example 3 — Change both name and tag (newName + newTag)
To replace both the image name and the tag in one transform:newName and newTag:
Quick reference table
Additional notes and best practices
- You can include multiple entries in the
images:list to transform several different base images in onekustomization.yaml. - Matching is strict: use the same base reference as in your manifests (for example
nginx,nginx:1.21, or a full registry path likegcr.io/myproj/nginx) to ensure replacements occur as expected. - Always preview transformations with
kustomize buildorkubectl kustomizebefore applying them withkubectl apply -k .. - Use Kustomize overlays (separate kustomization directories) for environment-specific image overrides (dev, staging, prod) to keep base manifests immutable.
Links and references
- Kustomize documentation: https://kubectl.docs.kubernetes.io/guides/introduction/kustomize/
- kubectl kustomize: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#kustomize
- Kustomize
imagestransformer reference: https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/imageTransformers/