Kustomize lets you customize raw, template-free Kubernetes YAML for multiple environments without forking the originals. It ships built into kubectl, and this cheatsheet covers the standalone kustomize CLI for building, creating, and editing kustomizations.
Building Manifests
# Build a kustomization.yaml into plain Kubernetes manifests
kustomize build ./overlays/production
# Build and write the output to a directory
kustomize build ./overlays/production --output ./rendered/
# Build and pipe straight into kubectl
kustomize build ./overlays/production | kubectl apply -f -
# Equivalent using kubectl's built-in kustomize support
kubectl apply -k ./overlays/production
Creating a Kustomization
# Create a new kustomization.yaml in the current directory
kustomize create
# Create a kustomization from existing resource files
kustomize create --resources deployment.yaml,service.yaml
# Automatically detect resources in the current directory
kustomize create --autodetect
Editing a Kustomization
# Add resources to the kustomization
kustomize edit add resource deployment.yaml
# Add a ConfigMap generator
kustomize edit add configmap app-config --from-literal=ENV=production
# Set the image used by a workload
kustomize edit set image myapp=myrepo/myapp:1.4.0
# Add a common label to every resource
kustomize edit add label team:platform
# Add a namePrefix or nameSuffix
kustomize edit set nameprefix prod-
Functions and Configuration
# Run a KRM function against local configuration
kustomize fn run ./overlays/production --image gcr.io/example/my-fn
# Read and write configuration with cfg commands
kustomize cfg tree ./overlays/production
Utilities
# Print the kustomize version
kustomize version
# Download remote bases to a local directory
kustomize localize ./overlays/production ./local-copy
# Generate a shell completion script
kustomize completion bash
# Show help for any command
kustomize help
Kustomize overlays pair well with the Kubectl Cheatsheet on this site: build your manifests with kustomize, then apply, inspect, and roll them out with the familiar kubectl commands.
