What Kustomize Is
A Kubernetes application is described by manifests: YAML files that say run this container image, this many copies, reachable on this port, with these settings. When the same application runs in more than one place — staging and production, say — the manifests are nearly identical and annoyingly different. The image tag moves with every release. Production wants more replicas and bigger memory limits. Staging wants a debug switch on. Everything wants its own name labels so you can tell the copies apart.
Kustomize is a tool for managing that
"nearly". You write the common
manifests once, exactly as Kubernetes
would accept them, with no placeholders
and no template syntax. That shared set
is the base. For each place, you
write an overlay: a short file that
names the base and lists the differences
— prefix every name with staging-, set
this label, use image tag 1.1.0, patch
this one field. kustomize build reads
base plus overlay and prints one clean
stream of YAML: the application as that
place needs it.
The output is plain manifests. Kustomize does not talk to a cluster, hold state, or keep secrets of its own; it is a text transformation, in the same family as a compiler: files in, files out, same input giving same output. You can pipe the result to a file, diff it against last week's result, review it in a pull request, and only then hand it to whatever applies manifests to your cluster. Chapter 10 makes a discipline of exactly that.
Why not templates, or copies
Two older answers to the same problem:
- Copies. Duplicate the folder per environment and edit each. It works until a fix lands in two copies out of three, and nobody remembers which copy is ahead. The drift is silent and the failure is a surprise.
- Templates. Write the YAML with
{{ .Values.replicas }}holes and a values file per environment (this is Helm's road; chapter 12 compares them fairly). The files on disk are no longer valid YAML, so your editor, linter and eyes all work on an approximation until render time.
Kustomize's wager is that the differences
between environments are structural and
small: names, labels, counts, tags, and
a few fields. Its overlays are
declarative lists of those differences,
written in a file called
kustomization.yaml, and the base stays
runnable YAML from first to last. The
price of the wager is real and chapter 13
states it: no if-statements, no loops,
no arithmetic. If your differences are
not small and structural, you feel the
ceiling quickly.
The two rules of this guide
Stated here, repeated where they bite:
- Your configuration, your clusters. Everything the lab builds is for an invented application, and nothing in this guide is ever applied to a live system. Customise manifests for systems that are yours to change.
- A generated Secret is encoded, not encrypted. Kustomize will happily build a Secret from values you type, and chapter 6 decodes one in front of you. Never type a real password into a file you would commit — the build output is exactly as readable as the input, to anyone.
Where it came from
Kustomize began as a standalone project
and was folded into kubectl, the
standard Kubernetes command-line tool,
which is why kubectl kustomize and
kubectl apply -k exist. The standalone
binary is the same engine released on its
own schedule — chapter 3 compares the
lab's two copies and finds them printing
byte-identical output from slightly
different versions. Kustomize is also
the customisation layer that GitOps
tools such as Argo CD and Flux call when
a repository holds a base and overlays
instead of flat manifests; GitOps for
Mere Mortals, in this series, covers
that world.
Next chapter names the parts. After that you install the tool and build.