kustomize
23 commands
23 shown
Build kustomization
Render all manifests for an overlay to stdout
kustomize build ./overlays/prod
Apply kustomization
Build and apply kustomization in one step via kubectl
kubectl apply -k ./overlays/prod
Diff kustomization
Show what changes before applying
kubectl diff -k ./overlays/prod
Add resource to kustomization
Append a resource file to kustomization.yaml
kustomize edit add resource ./deployment.yaml
Set image in kustomization
Update image tag in kustomization.yaml
kustomize edit set image myapp=registry/myapp:v2.0.0
Set namespace
Override namespace for all resources in the overlay
kustomize edit set namespace production
Add label to all resources
Inject a common label into all generated resources
kustomize edit add label env:production
Add patch
Register a strategic merge patch in kustomization.yaml
kustomize edit add patch --path patch.yaml --kind Deployment --name <name>
List resources
List all settable fields in the kustomization
kustomize cfg list-setters .
Build and apply
Build kustomize overlay and apply directly to cluster
kubectl apply -k ./overlays/prod
Preview output
Render kustomize output without applying
kubectl kustomize ./overlays/prod | head -100
Set image tag
Update image tag in kustomization.yaml
kustomize edit set image myapp=myapp:v1.2.3
Add configMapGenerator
Add a ConfigMap generator entry to kustomization.yaml
kustomize edit add configmap my-config --from-literal=key=value
List resources in overlay
Quickly list all resource kinds in a kustomize build
kustomize build ./overlays/prod | grep "^kind:"
Apply strategic merge patch
Use patchesStrategicMerge to partially override base resources
# Add patchesStrategicMerge in kustomization.yaml
Apply strategic merge patch
Create a strategic merge patch and register it in kustomization.yaml
cat > patch.yaml <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 3
template:
spec:
containers:
- name: myapp
resources:
limits:
memory: 512Mi
EOF
echo 'patches:\n- path: patch.yaml' >> kustomization.yaml
Inflate Helm charts in kustomize build
Render helmCharts: block to manifests; note: needs helm in PATH
kustomize build --enable-helm ./overlay
Apply a reusable component overlay
Mixin reusable patches/resources via components: (Kustomize v4+)
cat <<'EOF' >> kustomization.yaml
components:
- ../../components/monitoring
EOF
Copy a field with replacements
modern: replacements: copies a field cross-resource, replaces deprecated vars:
cat <<'EOF' >> kustomization.yaml
replacements:
- source: {kind: ConfigMap, name: cfg, fieldPath: data.host}
targets:
- select: {kind: Deployment}
fieldPaths: [spec.template.spec.containers.0.env.0.value]
EOF
Inline patch with target selector
JSON6902 patch applied to all matching targets, no separate file
cat <<'EOF' >> kustomization.yaml
patches:
- target: {kind: Deployment, labelSelector: app=api}
patch: |-
- op: replace
path: /spec/replicas
value: 3
EOF
Pin image by digest and rename
Pin by immutable digest; newName+digest also settable in images: block
kustomize edit set image app=registry.example.com/app@sha256:<id>
Secret generator without hash suffix
note: disableNameSuffixHash keeps stable name but breaks rollout-on-change
cat <<'EOF' >> kustomization.yaml
secretGenerator:
- name: db-creds
literals: [PASSWORD=s3cr3t]
generatorOptions:
disableNameSuffixHash: true
EOF
Register CRD OpenAPI for merge keys
Teach kustomize CRD merge/list semantics so patches merge correctly
cat <<'EOF' >> kustomization.yaml
openapi:
path: crd-schema.json
EOF
no commands match