CKAD · 24 November 2026 · 4 min read
Kustomize explained: bases, overlays and patches, with examples
Kustomize customizes plain Kubernetes YAML without templates. A base and two overlays worked through with kubectl apply -k, generated ConfigMaps, both kinds of patch, and the deprecated fields to avoid.
Kustomize customizes Kubernetes YAML without templates. You keep plain, valid manifests in a base. Each environment gets an overlay that lists what is different: a namespace, a name prefix, an image tag, a replica count, a patch. A kustomization.yaml file in each folder says what to combine. Kustomize is built into kubectl, so there is nothing to install: kubectl kustomize shows the result and kubectl apply -k applies it.
TL;DR
- A folder with a
kustomization.yamlis a kustomization.resources:lists files and other folders to include. - Base plus overlays:
base/holds the shared app,overlays/devandoverlays/prodhold the differences. - Preview with
kubectl kustomize overlays/prod. Apply withkubectl apply -k overlays/prod. - Built-in fields:
namespace,namePrefix,labels,images,replicas,configMapGenerator,secretGenerator,patches. - Generated ConfigMaps get a hash suffix, so changing a value rolls the Pods that use it.
- Exam: CKA asks you to use Helm and Kustomize to install cluster components. CKAD lists Kustomize under Application Deployment (20%).
A base
The base is an ordinary app you could apply with kubectl apply -f, plus a kustomization.yaml:
base/ kustomization.yaml deployment.yaml # a Deployment "web", image nginx:1.27, envFrom configMapRef web-config service.yaml # a Service "web" on port 80# base/kustomization.yamlapiVersion: kustomize.config.k8s.io/v1beta1kind: Kustomizationresources:- deployment.yaml- service.yamlconfigMapGenerator:- name: web-config literals: - LOG_LEVEL=infoconfigMapGenerator makes a ConfigMap called something like web-config-hf678c7m2b. The suffix is a hash of the contents, and Kustomize rewrites the Deployment's configMapRef to match. Change LOG_LEVEL and the name changes, the Pod template changes, and the Deployment rolls out new Pods. With a hand-written ConfigMap, the Pods would keep the old values until something restarted them.
A production overlay
# overlays/prod/kustomization.yamlapiVersion: kustomize.config.k8s.io/v1beta1kind: Kustomizationnamespace: prodnamePrefix: prod-labels:- pairs: env: prodresources:- ../../baseimages:- name: nginx newTag: "1.27-alpine"replicas:- name: web count: 3configMapGenerator:- name: web-config behavior: merge literals: - LOG_LEVEL=warnpatches:- path: resources.yaml# overlays/prod/resources.yaml: a partial Deployment, merged over the baseapiVersion: apps/v1kind: Deploymentmetadata: name: webspec: template: spec: containers: - name: web resources: requests: cpu: 100m memory: 128MiPreview it:
kubectl kustomize overlays/prodThe output has three resources: a ConfigMap prod-web-config-<hash> with LOG_LEVEL: warn, a Service prod-web and a Deployment prod-web. All three are in namespace prod with the label env: prod. The Deployment has 3 replicas, image nginx:1.27-alpine, the CPU and memory requests, and a configMapRef that points at the renamed ConfigMap. Kustomize renamed the reference for you. If you only add a prefix with sed, the reference breaks.
Apply it, and delete it the same way:
kubectl create namespace prodkubectl apply -k overlays/prodkubectl delete -k overlays/prodTwo kinds of patch
The resources.yaml above is a strategic merge patch: a partial resource that Kustomize merges by name, so the container called web gets the extra fields. For a precise edit, use a JSON 6902 patch with a target:
# overlays/dev/kustomization.yamlapiVersion: kustomize.config.k8s.io/v1beta1kind: Kustomizationnamespace: devresources:- ../../basepatches:- target: kind: Deployment name: web patch: |- - op: add path: /spec/template/spec/containers/0/env value: - name: DEBUG value: "true"Both go under patches:. The older patchesStrategicMerge and patchesJson6902 fields are deprecated.
Common questions
What is the difference between kubectl apply -k and kubectl apply -f?
-f applies the files as they are. -k runs Kustomize on a folder first and applies the result. Point -k at the folder that holds kustomization.yaml, not at the file.
Should I use commonLabels or labels?
labels. commonLabels is deprecated, and current kubectl prints a warning when it sees it. It also adds the label to selectors. A Deployment's selector cannot be changed after it is created, so adding a label to an existing app with commonLabels makes the apply fail. labels leaves selectors alone unless you set includeSelectors: true. Run kustomize edit fix to update old files.
Is bases: still used?
No. List base folders under resources:, as in the overlay above. bases: is deprecated.
Why do my Pods restart every time I change a generated ConfigMap?
That is the hash suffix at work, and usually it is what you want. If something outside Kustomize refers to the ConfigMap by a fixed name, turn the suffix off for that generator with options: disableNameSuffixHash: true.
Is the Kustomize in kubectl the same as the standalone kustomize tool?
It is the same code, but kubectl bundles a particular version (kubectl version --client shows it). The standalone tool is often newer. In the exam, use kubectl kustomize and kubectl apply -k.
Can Kustomize use a Helm chart?
Yes, with the helmCharts field and the --enable-helm flag, which runs Helm to render the chart and then patches the result. See Helm vs Kustomize for when that makes sense.
Keep going
The fastest way to learn Kustomize is to build one base and two overlays and diff their output. In the Gazeek CKAD Helm and Kustomize module you set a namespace, labels and an image tag from a kustomization on a real cluster, and the CKA workloads for admins module covers Helm, Kustomize and CRDs together. Read on with Helm explained and Helm vs Kustomize.