Build and apply
kustomize build <dir>
Render a kustomization to stdout
kustomize build <dir> -o <path>
Write output to a file or directory
kubectl apply -k <dir>
Build and apply to the cluster
kubectl kustomize <dir>
Build using kubectl's bundled kustomize
kubectl diff -k <dir>
Show what apply would change
kubectl delete -k <dir>
Delete everything the build produces
kubectl get -k <dir>
List live objects of the build
kustomize build --enable-helm <dir>
Inflate helmCharts entries
Needs the helm binary on PATH.
kustomize build --load-restrictor LoadRestrictionsNone
<dir>
Allow files outside the root
kustomize build
<git-url>//<path>?ref=<tag>
Build straight from a git repo
kustomize version
Print the version
Create and edit
kustomize create
Write an empty kustomization.yaml
kustomize create --autodetect
Create it listing YAML files found
kustomize edit add resource <path>
Add a file or directory to resources
kustomize edit add patch --path <file> --kind
<kind>
Add a patch entry
kustomize edit add configmap <name>
--from-literal=<k>=<v>
Add a generated ConfigMap
kustomize edit add label <k>:<v>
Add a label to all resources
kustomize edit add annotation <k>:<v>
Add an annotation to all resources
kustomize edit set image
<name>=<newname>:<tag>
Change an image name and tag
kustomize edit set namespace <ns>
Set the namespace
kustomize edit set nameprefix <prefix>
Set the name prefix
kustomize edit set replicas <name>=<n>
Set a replica count
kustomize edit fix
Migrate deprecated fields
Rewrites patchesStrategicMerge, commonLabels and bases to
current fields.
kustomization.yaml
Skeleton
apiVersion: kustomize.config.k8s.io/v1beta1kind: Kustomizationresources:- ../../base- extra.yaml
resources:
Files, directories or URLs to include
namespace: <ns>
Set namespace on every resource
namePrefix: <p> / nameSuffix: <s>
Prefix or suffix all names
References between resources are updated too.
labels:
Add labels, optionally to selectors
Prefer over commonLabels: selectors are only touched with
includeSelectors: true.
commonAnnotations:
Add annotations to all resources
replicas:
Override replica counts
components:
Include reusable Component directories
generatorOptions:
Defaults for generated ConfigMaps/Secrets
helmCharts:
Render Helm charts in place
buildMetadata:
Record origin in annotations or labels
Patches
Strategic merge from a file
patches:- path: patch.yaml target: kind: Deployment name: web
Inline JSON6902
patches:- target: {kind: Deployment, name: web} patch: |- - op: replace path: /spec/replicas value: 3
target: {kind, name, labelSelector}
Select what a patch applies to
name and namespace are regexes, anchored automatically.
op: add / replace / remove
JSON6902 operations
path: /metadata/labels/a~1b
Escape / as ~1 in JSON paths
options: {allowNameChange: true}
Let a patch rename a resource
Images and generators
Images
images:- name: nginx newName: registry.example/nginx newTag: "1.27"
digest: sha256:<hash>
Pin an image by digest instead of tag
ConfigMap from literals and files
configMapGenerator:- name: app-config literals: - LOG_LEVEL=debug files: - app.properties
envs: [<file>.env]
Load KEY=value lines as entries
secretGenerator:
Same fields as configMapGenerator, makes Secrets
behavior: create / replace / merge
How an overlay treats a base's generator
options: {disableNameSuffixHash: true}
Keep the plain name without a hash
The hash suffix triggers rollouts when config changes;
disabling it loses that.
files: [<key>=<file>]
Choose the data key for a file