Kustomize · Cheat sheet
Kustomize cheat sheet
Template-free Kubernetes customization, beginner to advanced: build and apply, the kustomization.yaml fields, generators, image/replica setters, patches, and the bases/overlays/components model — with example output.
Build & applyBeginner
kubectl kustomize base/
Render a kustomization to stdout (built into kubectl).
kustomize build overlays/prod
Render with the standalone CLI (newer features).
kubectl apply -k overlays/prod
Build and apply in one step.
kubectl delete -k overlays/prod
Delete everything the overlay renders.
kustomize build overlays/prod | kubectl diff -f -
Preview the change before applying.
kustomize version
Print the CLI version.
kustomization.yaml basicsBeginner
resources: [deploy.yaml, svc.yaml]
The base manifests this kustomization includes.
namespace: prod
Set the namespace on every resource.
namePrefix: prod- / nameSuffix: -v2
Prefix/suffix all names (and references).
metadata: name: prod-web-v2
commonLabels: { app: web }
Add labels to all resources AND their selectors.
commonAnnotations: { team: sre }
Annotate every resource.
labels: [{ pairs: {env: prod}, includeSelectors: false }]
Newer, finer-grained label control.
GeneratorsIntermediate
configMapGenerator: [{ name: cfg, literals: [LOG=info] }]
Generate a ConfigMap from literals/files.
name: cfg-2g5h8k9t2c # content hash suffix
configMapGenerator: [{ name: cfg, files: [app.conf] }]
ConfigMap from file contents.
configMapGenerator: [{ name: env, envs: [.env] }]
ConfigMap from a dotenv file.
secretGenerator: [{ name: db, literals: [pass=s3cr3t] }]
Generate a Secret the same way.
generatorOptions: { disableNameSuffixHash: true }
Turn off the content-hash suffix.
Images & replicasIntermediate
images: [{ name: nginx, newTag: "1.27" }]
Pin an image tag without editing manifests.
images: [{ name: nginx, newName: reg.io/nginx }]
Swap the image name/registry.
images: [{ name: nginx, digest: sha256:... }]
Pin by immutable digest.
replicas: [{ name: web, count: 5 }]
Override replica count per workload.
kustomize edit set image nginx=nginx:1.27
Edit kustomization.yaml from the CLI.
PatchesIntermediate
patches: [{ path: cpu.yaml, target: { kind: Deployment } }]
Patch resources matching a selector.
patchesStrategicMerge: [patch.yaml]
Overlay a partial manifest (older field).
{ op: replace, path: /spec/replicas, value: 3 }
A JSON 6902 patch operation.
target: { labelSelector: "tier=web" }
Aim a patch with a label selector.
Bases, overlays & componentsAdvanced
resources: [../../base]
An overlay references a base kustomization.
components: [../../components/logging]
Reusable mixins applied across overlays.
replacements: [{ source: .., targets: [..] }]
Copy a value from one field into others.
helmCharts: [{ name: redis, valuesInline: {} }]
Inflate a Helm chart through Kustomize.
kustomize build --enable-helm overlays/prod
Enable the Helm chart inflator.
Go deeper
Full, hands-on DevSecOps courses