kustomize edit: set image, add & CI Errors
Programmatically edit a kustomization.yaml - ideal for CI image bumps.
kustomize edit modifies the kustomization.yaml in place, so CI can set the freshly built image tag (or add resources) without fragile sed/YAML hacking.
What it does
kustomize edit runs from inside a kustomization directory and mutates its kustomization.yaml: edit set image updates an image name/tag/digest, edit add resource adds a file, edit set namespace sets the namespace. The classic CI use is pinning the image to the commit SHA the pipeline just built.
Common usage
# Pin the image to the build’s tag (run inside the overlay dir)
cd overlays/prod
kustomize edit set image myapp=registry.example.com/myapp:${GIT_SHA}
# Add a resource and set the namespace
kustomize edit add resource service.yaml
kustomize edit set namespace prodCommon error in CI: must be run in a kustomization dir
edit fails with "unable to find one 'kustomization.yaml' in directory" when the step runs from the wrong path, or set image silently no-ops if the image name does not match one referenced in the manifests. Fix: cd into the directory that contains kustomization.yaml before running edit (it edits the file in the current dir), and use the exact image name as it appears in the manifests so the images: override actually applies. Commit or pipe the result; edit changes the file but does not deploy.
Key subcommands
| Subcommand | Purpose |
|---|---|
| set image NAME=REF | Set an image name/tag/digest |
| set namespace NS | Set the namespace |
| add resource FILE | Add a resource |
| set nameprefix / namesuffix | Set a name prefix/suffix |