Module 12 ยท Lesson 12.2
Kustomize
Kustomize solves a similar problem to Helm โ the same base app needs
slightly different settings per environment โ with a deliberately
different approach: no templating language at all, just patches over
plain YAML. It ships built into kubectl (kubectl apply -k), no install
required.
Bases and overlays
A base is an ordinary set of manifests plus a kustomization.yaml
listing them as resources:. An overlay references that base and adds
patches: โ surgical edits like "bump replicas to 3" or "use this image
tag instead" โ without touching or duplicating the base files themselves.
You might have base/, overlays/dev/, overlays/prod/, each overlay
patching only what differs for that environment.
This is the opposite design choice from Helm's {{ .Values.x }}
placeholders sprinkled through every file: Kustomize's base files are
100% valid, plain Kubernetes YAML you could kubectl apply directly with
no tool at all. The overlay is where environment-specific differences
live, expressed as patches, not as parameterized templates.
Patches, and how they can go quietly wrong
A patch targets a resource (by kind/name) and a field path to change. The
failure mode here is different from Helm's "renders empty" โ a patch with
a field path that doesn't exactly match the real resource doesn't
necessarily error. It can end up adding a new, wrong field alongside the
real one, leaving the object looking patched when it isn't. kubectl kustomize <dir> renders the final YAML with zero cluster contact โ same
idea as helm template โ and is how you catch this before kubectl apply
does (or, as you'll see in this lesson's lab, before the API server's own
schema validation does).
No templates means no values, and no release history
Because there's no templating language, there's also no values.yaml
equivalent and no revision/rollback concept โ Kustomize doesn't track
"releases" the way Helm does. Fixing a bad overlay is just editing the
patch and re-running kubectl apply -k, same as any other manifest change.
Helm vs. Kustomize: when to reach for which
Helm fits best when you're distributing something to other people (a chart with real configurability, a version, a repo to publish to) โ this cluster's own Ingress controller, Traefik, is already running as a Helm release for exactly that reason; most third-party addons you'll install from here on ship as charts too. Kustomize fits best for your own app's environment differences, where you'd rather keep every file as plain, readable YAML and express "what's different in prod" as an explicit, reviewable patch instead of a templating mini-language.
๐งช Lab: lab-25-kustomize
Preview onlyGoal
Use a Kustomize base + overlay, hit a realistic patch bug, diagnose it by rendering first (no templating language involved โ just patches over plain YAML), and fix it.
Tasks
- Look at
manifests/base/โ a plain Deployment (web, 2 replicas) and Service, with akustomization.yamllisting them as resources. - Look at
manifests/overlays/dev/kustomization.yamlโ it's meant to bumpwebto 3 replicas via a JSON6902 patch, for a "dev" environment. - Render it without applying anything:
kubectl kustomize manifests/overlays/devLook closely at the rendered Deployment'sspec:โ there are now two replica-looking fields. The patch's JSON6902path:doesn't exactly match a real field, so instead of replacing anything it just added a new one. - Apply it anyway to see the live symptom:
kubectl apply -k manifests/overlays/devThe Service creates fine; the Deployment is rejected outright โ the API server's strict schema validation catches the bogus field kustomize produced and refuses to create it. Read the error. - Fix the typo'd
path:inmanifests/overlays/dev/kustomization.yamlso it matches the Deployment's real field exactly. - Re-render (
kubectl kustomize manifests/overlays/dev) โ the bogus field should be gone andreplicas: 3should be the only one there. Then apply it for real:kubectl apply -k manifests/overlays/dev
Check
Run the check once the Deployment is applied and scaled to 3.
This lab runs against a real local Kubernetes cluster with an automated grader โ clone the repo and run make start to do it for real.
๐ Quiz
1. What's the core design difference between Kustomize and Helm?
2. Which command renders a Kustomize directory to plain YAML without touching the cluster?
3. An overlay patch's field path has a typo and doesn't exactly match a real field on the target resource. What's the most accurate description of what can happen?scenario
4. If a Kustomize overlay change goes wrong, how do you 'roll it back'?
5. You're building a reusable chart that other teams will install with their own custom values. Is Helm or Kustomize the better fit, and why?scenario
Progress isn't saved in this preview โ run the course locally to track completion and grade labs for real.