Helm & Kustomize
Be able to explain it and pass its lab once. Phase 7 of the Learning Path.
Docs: Helm Β· Helm cheat sheet Β· Kustomize in kubectl
Overviewβ
Raw YAML stops scaling once the same app runs in three environments or you install someone else's software. Helm is a package manager: a chart is a set of templates plus default values, and each install is a named release with a revision history you can roll back. Kustomize has no templates: it takes plain YAML (a base) and applies patches per environment (overlays), and it is built into kubectl as -k. Use Helm to install third-party software and when you need to ship a configurable package. Use Kustomize for your own apps when each environment differs only in a few fields. Many teams use both: Helm for vendor charts, Kustomize for their own services.
Key conceptsβ
Helm vs Kustomizeβ
| Helm | Kustomize | |
|---|---|---|
| Model | Go templates + values.yaml | Plain YAML + patches |
| Built into kubectl | No, separate helm CLI | Yes: kubectl apply -k |
| Release tracking | Yes. History, helm rollback. | No. Just applied objects. |
| Readability | Templates get hard to read | Base is valid YAML you can apply alone |
| Best for | Installing third-party software, distributing packages | Your own apps across dev/staging/prod |
Helm termsβ
| Term | Meaning |
|---|---|
| Chart | Package: templates, Chart.yaml, default values.yaml |
| Repository | Where charts are published: an HTTP index or an OCI registry |
| Release | One installed instance of a chart in a namespace, with a name |
| Revision | A numbered version of a release. Every upgrade or rollback adds one. |
| Values | Inputs to the templates. Precedence: chart defaults < -f file < --set |
Kustomize featuresβ
A base of plain YAML, plus one overlay per environment that patches it. The base and prod overlay below use every field Lab 7-1 needs.
Deeper dive
Field in kustomization.yaml | Does |
|---|---|
resources | Files or directories to include (the base) |
namespace / namePrefix / labels | Applied to every object |
images | Override image name or tag without a patch |
replicas | Override replica counts by name |
patches | Strategic-merge or JSON patches for anything else |
configMapGenerator / secretGenerator | Build ConfigMaps with a content hash in the name, so a change triggers a rollout |
kubectl essentialsβ
Helm install and inspect:
helm repo add podinfo https://stefanprodan.github.io/podinfo
helm repo update
helm search repo podinfo
helm show values podinfo/podinfo | less # what can I set?
helm install web podinfo/podinfo -n demo --create-namespace --set replicaCount=2
helm install web podinfo/podinfo -n demo -f my-values.yaml
helm list -A # releases in every namespace
helm get values web -n demo # values you supplied
helm get manifest web -n demo # rendered YAML actually applied
helm template web podinfo/podinfo --set replicaCount=2 # render locally, install nothing
Helm upgrade and roll back:
helm upgrade web podinfo/podinfo -n demo --reuse-values --set ui.message=hi
helm upgrade --install web podinfo/podinfo -n demo -f values.yaml # idempotent: CI-friendly
helm history web -n demo
helm rollback web 1 -n demo
helm uninstall web -n demo
Kustomize:
kubectl kustomize overlays/prod # render, apply nothing
kubectl apply -k overlays/prod
kubectl diff -k overlays/prod # what would change
kubectl delete -k overlays/prod
A base and a prod overlay:
app/
βββ base/
β βββ kustomization.yaml
β βββ deployment.yaml
βββ overlays/
βββ prod/
βββ kustomization.yaml
# base/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
configMapGenerator:
- name: web-config
literals:
- LOG_LEVEL=debug
# overlays/prod/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: prod
namePrefix: prod-
resources:
- ../../base
images:
- name: nginx
newTag: "1.28"
replicas:
- name: web
count: 3
configMapGenerator:
- name: web-config
behavior: merge
literals:
- LOG_LEVEL=info
patches:
- target: {kind: Deployment, name: web}
patch: |-
- op: add
path: /spec/template/spec/containers/0/resources
value: {requests: {cpu: 100m, memory: 128Mi}}
π§ͺ Labβ
Requires: Standard lab setup Β· envFrom Β· How the tiers work.
One base, two environments.
Goal
- Create
base/with a Deploymentweb(nginx:1.27, 1 replica) that readsLOG_LEVELfrom a generated ConfigMapweb-config. - Create
overlays/prod/that sets namespacelab7-1, prefixprod-, 3 replicas, tag1.28andLOG_LEVEL=info. - Render the overlay, then apply it. Change
LOG_LEVELtowarnand re-apply. What happens to the Pods, and why?
Verify
kubectl -n lab7-1 get deploy prod-web -o jsonpath='{.spec.replicas} {.spec.template.spec.containers[0].image}{"\n"}' # 3 nginx:1.28
kubectl -n lab7-1 get configmap # prod-web-config-<hash>, one per LOG_LEVEL applied
π‘ Hints
- Generate the Deployment with
--dry-run=client -o yaml, then addenvFrompointing atweb-config. The ConfigMap comes fromconfigMapGenerator, not from a file. - The fields you need are in the overlay example above (and the Deeper dive under Kustomize features):
namespace,namePrefix,replicas,images, and a generator withbehavior: merge. kubectl kustomize <dir>renders;kubectl apply -k <dir>applies. Compare the ConfigMap name before and after.
π’ Guided
-
Create the directory layout and enter it.
mkdir -p app/base app/overlays/prod && cd app -
Write the base Deployment; it reads every key of web-config as env vars.
cat > base/deployment.yaml <<'EOF'apiVersion: apps/v1kind: Deploymentmetadata:name: webspec:replicas: 1selector:matchLabels: {app: web}template:metadata:labels: {app: web}spec:containers:- name: nginximage: nginx:1.27envFrom:- configMapRef: {name: web-config}EOF -
Write
base/kustomization.yamlas shown above. -
Write
overlays/prod/kustomization.yamlas shown above, but withnamespace: lab7-1. -
Create the target namespace.
kubectl create namespace lab7-1 -
Render the overlay without applying: names prefixed, configMapRef rewritten to the hashed name.
kubectl kustomize overlays/prod | less -
Apply the rendered overlay.
kubectl apply -k overlays/prod -
Edit the overlay: change
LOG_LEVEL=infotoLOG_LEVEL=warn. -
Apply again.
kubectl apply -k overlays/prod -
List ReplicaSets: a new one appeared.
kubectl -n lab7-1 get rsThe ConfigMap name (hash) changed, so the Pod template changed, so a rollout happened.
-
Run the β Check below, then delete everything the lab created.
cd .. && kubectl delete namespace lab7-1
β Check
t() { [ "$2" = "$3" ] && echo "PASS $1" || echo "FAIL $1: got '$2', want '$3'"; }
t "3 replicas on 1.28" "$(kubectl -n lab7-1 get deploy prod-web -o jsonpath='{.spec.replicas} {.spec.template.spec.containers[0].image}')" "3 nginx:1.28"
t "Pods see LOG_LEVEL=warn" "$(kubectl -n lab7-1 exec deploy/prod-web -- printenv LOG_LEVEL)" "warn"
t "config change rolled" "$(kubectl -n lab7-1 get rs --no-headers | wc -l | tr -d ' ')" "2"
t "two hashed ConfigMaps" "$(kubectl -n lab7-1 get configmap -o name | grep -c 'prod-web-config-')" "2"
Requires: Standard lab setup Β· the helm CLI (v3 or v4) and internet access Β· How the tiers work.
Install a chart, break its values, roll back.
Goal
- Add the
podinforepo. Install chartpodinfo/podinfoversion6.15.0as releasewebin namespacelab7-2, with 2 replicas. - Upgrade the release to set
ui.message=hello, keeping 2 replicas. - Upgrade again, passing only
--set ui.message=oops. How many replicas are there now, and why? - Roll back to the revision that had 2 replicas and
hello.
Verify
helm history web -n lab7-2 # 4 revisions, the last "Rollback to 2"
kubectl -n lab7-2 get deploy web-podinfo # 2/2
helm get values web -n lab7-2 # replicaCount: 2, message: hello
π‘ Hints
helm repo add -h, thenhelm install -h: look at--version,--create-namespaceand--set.helm show valuesnames the replica key.helm upgrade -h: which flag keeps the values from the last revision?- Compare
helm get valuesbefore and after. Values you don't pass again are not kept by default. helm historynumbers the revisions;helm rollback <release> <revision>.
π’ Guided
-
Add the chart repository and find the replica key.
helm repo add podinfo https://stefanprodan.github.io/podinfohelm repo updatehelm show values podinfo/podinfo --version 6.15.0 | grep -E '^replicaCount| message'replicaCount: 1message: "" -
Install a pinned chart version with 2 replicas.
helm install web podinfo/podinfo --version 6.15.0 -n lab7-2 --create-namespace --set replicaCount=2kubectl -n lab7-2 rollout status deployment/web-podinfoNAME: webNAMESPACE: lab7-2STATUS: deployedREVISION: 1DESCRIPTION: Install complete -
Upgrade, keeping the earlier values and adding a message.
helm upgrade web podinfo/podinfo --version 6.15.0 -n lab7-2 --reuse-values --set ui.message=hellohelm get values web -n lab7-2USER-SUPPLIED VALUES:replicaCount: 2ui:message: hello -
Upgrade the careless way: a new
--setand nothing else.helm upgrade web podinfo/podinfo --version 6.15.0 -n lab7-2 --set ui.message=oopskubectl -n lab7-2 get deploy web-podinfo -o jsonpath='{.spec.replicas}{"\n"}'helm get values web -n lab7-21USER-SUPPLIED VALUES:ui:message: oopsWithout
--reuse-values(or-fwith the full values file), Helm starts from the chart defaults.replicaCount: 2was dropped, so the Deployment scaled to 1. -
Roll back to revision 2 and read the history.
helm rollback web 2 -n lab7-2kubectl -n lab7-2 rollout status deployment/web-podinfohelm history web -n lab7-2REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION1 Sun Sep 27 09:54:27 2026 superseded podinfo-6.15.0 6.15.0 Install complete2 Sun Sep 27 09:54:39 2026 superseded podinfo-6.15.0 6.15.0 Upgrade complete3 Sun Sep 27 09:54:40 2026 superseded podinfo-6.15.0 6.15.0 Upgrade complete4 Sun Sep 27 09:54:41 2026 deployed podinfo-6.15.0 6.15.0 Rollback to 2A rollback is a new revision (4) with revision 2's values and templates. History only moves forward.
-
Run the β Check below, then delete everything the lab created.
kubectl delete namespace lab7-2
β Check
t() { [ "$2" = "$3" ] && echo "PASS $1" || echo "FAIL $1: got '$2', want '$3'"; }
t "4 revisions" "$(helm history web -n lab7-2 -o json | grep -o '"revision":' | wc -l | tr -d ' ')" "4"
t "last is Rollback to 2" "$(helm history web -n lab7-2 --max 1 -o json | grep -o 'Rollback to 2')" "Rollback to 2"
t "2 replicas again" "$(kubectl -n lab7-2 get deploy web-podinfo -o jsonpath='{.status.readyReplicas}')" "2"
t "message is hello" "$(kubectl -n lab7-2 get deploy web-podinfo -o jsonpath='{.spec.template.spec.containers[0].env[?(@.name=="PODINFO_UI_MESSAGE")].value}')" "hello"
Gotchasβ
helm upgradewithout--reuse-valuesor-fresets your values. Earlier--setflags are dropped. Keep values in a file in Git and always pass-f.- Releases are namespaced.
helm listshows the current namespace only. Use-A. - Manual edits to Helm-managed objects drift. The next upgrade overwrites them. Change values instead.
- Failed upgrades leave a
failedrelease.helm historyshows it.helm rollbackto the lastdeployedrevision, or pass--rollback-on-failure(Helm 4;--atomicin Helm 3, deprecated in 4) to roll back automatically on failure. - kubectl's built-in Kustomize lags the standalone one. Check
kubectl versionif a newer field isn't recognised. - Generated ConfigMap names change on every edit. Reference them only through Kustomize, which rewrites the references. A hand-written name won't match. Old generated ConfigMaps are left behind; clean them up or prune.
Scenario questionsβ
Q1 β
Install a vendor's chart into monitoring with 3 replicas and your own values file. What commands, and what do you check first?
Model answer
- Clarify: which chart version is approved? Is there an existing release to upgrade instead?
- Observe:
helm show valuesto find the replica key. It differs per chart (replicaCount,server.replicas). - Hypothesise: a first install with
-f values.yaml, pinned with--version. - Fix:
helm upgrade --install <name> <chart> -n monitoring --create-namespace --version <v> -f values.yaml, thenhelm get manifestto confirm the rendered replicas. - Prevent: always pin
--version. An unpinned install picks up whatever was published that morning.
Q2 β
β
A helm upgrade failed halfway. The release shows failed and some Pods run the new version. What now?
Model answer
- Clarify: is the app serving? Is the failure in the chart (rendering or hooks) or the app (Pods not Ready)?
- Observe:
helm historyshows the failed revision.kubectl get podsand events show what broke. - Hypothesise: a failing pre-upgrade hook (such as a migration Job) or new Pods that never became Ready before
--waittimed out. - Fix:
helm rollback <release> <last-good-revision>, then fix and upgrade again. - Prevent:
helm upgrade --rollback-on-failure --timeout 10min CI (--atomicon Helm 3), which rolls back on failure. Test upgrades in staging with production-like values.
Q3 β β Your team runs one internal service in dev, staging and prod. Helm or Kustomize?
Model answer
- Clarify: how different are the environments? Does anyone outside the team install it?
- Observe: differences are usually replicas, image tag, resources and a few config values.
- Hypothesise: Kustomize fits: the base stays readable YAML and overlays show the differences explicitly. A chart adds templating and a values API nobody else consumes.
- Fix: base + three overlays in Git, applied by CI or a GitOps controller.
- Prevent: trade-off to name: if the service becomes a product other teams install with their own settings, Helm's packaging and versioning start paying off.
Q4 β β β A chart needs a database password. How do you keep it out of Git?
Model answer
- Clarify: what secret store exists (Vault, cloud secret manager)? Is GitOps in use?
- Observe:
--set password=...ends up in shell history, and in the release record: anyone with read access to Helm's release Secrets can see it. - Hypothesise: the secret should not pass through Helm at all.
- Fix: keep the password in a secret manager, sync it into a Kubernetes Secret with External Secrets Operator, and have the chart reference the existing Secret by name (most charts support
existingSecret). Encrypted-in-Git options (SOPS, Sealed Secrets) work when there is no secret manager. - Prevent: a CI check that rejects plaintext secrets in values files. β See Config & Secrets.
Summaryβ
- Helm packages and tracks releases; Kustomize patches plain YAML. Choose by who installs it and how much varies.
- Pin chart versions and keep values in files.
--setand unpinned charts are unrepeatable. helm upgrade --install --rollback-on-failureis the CI form. Idempotent, and it rolls back on failure.- Kustomize generators hash config into names. A config change becomes a rollout automatically.
kubectl kustomizeandhelm templaterender without applying. Read the output before you ship it.
Next in path β ML Model Serving (Phase 8: interview mode)