The Moving Parts
Seven ideas carry the whole tool. Meet them here and every later chapter is just one of them, exercised.
The kustomization file
Every base and every overlay is a folder
containing a file named
kustomization.yaml. It is the table
of contents and the instruction sheet in
one: which resources to gather, what to
generate, what to rename, what to patch.
kustomize build <folder> reads that
file, does everything it says, and prints
the result. A folder without one is not
buildable; the file is the unit of
work.
Resources
A resource is one Kubernetes object —
a Deployment, a Service, a ConfigMap —
whether it comes from a YAML file listed
under resources: or from another
folder's kustomization. Bases list files.
Overlays list a base folder, which is how
layering composes: an overlay is itself a
resource source for the overlay above it,
and real projects stack three or four
deep.
Generators
Writing a ConfigMap by hand means pasting
a file's contents into YAML, indented
just so, and re-pasting it at every edit.
A generator — configMapGenerator,
secretGenerator — builds that resource
at build time from sources you point at:
whole files, or key=value literals.
Chapter 6 shows both, and shows the
generator's signature move: a short
hash suffix added to the generated
name, computed from the contents, so any
content change produces a new name — and
therefore a fresh rollout — all by
itself.
Transformers
A transformer adjusts resources that already exist. The everyday ones are fields of the kustomization file:
namePrefix/nameSuffix— rename every resource, and (the important half) rewrite every reference to a renamed resource, so a Service still finds its Deployment's world consistent. Chapter 5 watches a prefix reach into volume mounts and secret references.commonLabels/commonAnnotations— stamp the same label or annotation onto everything. (In current versions these two fields are deprecated in favour of thelabels:andannotations:transformer fields; the old fields still work, and the tool says so out loud — chapter 5 keeps the warning in the transcript rather than hiding it.)images:— change an image's name or tag by naming the image, not by finding the line it lives on.replicas:— set a workload's replica count, again by name.namespace:— move everything into one namespace (the lab does not use it; it behaves like the prefix, for the namespace field).
Patches
When a difference does not fit a transformer field — production's Deployment needs bigger memory limits, staging's needs a debug environment variable — a patch edits one resource directly. Kustomize offers two dialects, and chapter 7 proves each with a diff:
- A strategic merge patch is a scrap of YAML shaped like the resource itself, holding only the fields to change. It merges by structure, which makes it short and readable.
- A JSON 6902 patch is a list of
operations (
add,replace,remove) with exact paths, named after the RFC that defines the format. More verbose, more precise, and the only way to touch some list positions.
Replacements
A replacement copies a value from one
built resource into another: take the
greeting entry of this ConfigMap and
put it in that container's environment
variable. It is how a value can be
written once — in the place that owns
it — and appear wherever it is consumed,
with the copying redone at every build.
Chapter 8 builds one and watches the
staging value and the production value
each land in the right Deployment.
The build
Everything ends in kustomize build.
It reads, generates, patches, transforms
and prints — deterministically, offline,
in milliseconds, touching nothing outside
the folder it was pointed at. Because
the build is pure, the guide's working
method is available to you in full:
build two variants and diff them. If
an overlay claims to change only the
replica count, the diff is the audit.
That is the whole machine. Chapter 3 puts it on your computer.