Cloud and DevOps
Helm
Helm turns one set of templated Kubernetes manifests plus a values file per environment into a named, versioned, reversible release. The running example is a bank-api chart with dev and prod values. What was run: Helm v3.22.1 (it reports itself as v3.22), built with go install into a scratch folder, with no cluster. So every helm lint, helm template, helm dependency and helm package output here is pasted from a real run, and everything that needs a cluster (install, upgrade, rollback, history, hooks, diff, push) was not run and is labelled so.
Why Helm, and what a chart is
Part 1 of 6 · the problem and the vocabulary
The problem: copied YAML
One service in three environments is three folders of nearly identical YAML. A fix lands in one copy, and nobody can say what is running or how to go back.
| Pain | What Helm gives |
|---|---|
| Same YAML copied per environment | One template, one small values file each |
| Ten objects applied one by one | One release, installed and removed as a unit |
| "What is deployed, and since when?" | helm list, helm history |
| Rolling back by hand | helm rollback to a stored revision |
| Installing other people's software | Published charts with documented values |
Scope: Deployments, Services, ConfigMaps and the other objects are explained on the Kubernetes page. This page only covers how Helm produces and tracks them.
Chart, values, release, revision
Helm 3 is a client only. It renders templates on your machine, sends the result to the API server and stores a record of what it sent.
| Word | Meaning |
|---|---|
| Chart | A folder (or .tgz) of templates and default values |
| Values | The inputs: defaults, then your overrides |
| Release | One installed instance of a chart, with a name, in a namespace |
| Revision | A numbered snapshot of a release: 1 on install, +1 per upgrade or rollback |
| Repository | Where packaged charts are published |
Chart layout
Why Helm · real listing of the chart used on this page
| Path | Purpose |
|---|---|
Chart.yaml | Name, versions, dependencies |
values.yaml | Defaults, and the documentation of every knob |
templates/*.yaml | Manifests with {{ }} actions |
templates/_helpers.tpl | Named snippets. Files starting with _ render no manifest. |
templates/NOTES.txt | Text printed after install |
charts/ | Subcharts, filled by helm dependency update |
crds/ | CRDs: installed once, never templated, never upgraded |
values.schema.json | Optional JSON Schema for values |
Two version fields, two meanings. version is the chart, appVersion is the application inside it.
Rules: every value a template reads should appear in values.yaml, even if empty: that file is the chart's public interface. helm create NAME scaffolds a much larger chart to cut down.
The template language
Part 2 of 6 · Go templates that must produce valid YAML
Values and built-in objects
A template is YAML with holes. Each {{ }} reads from the dot, which at the top of a file holds these objects.
| Object | Holds |
|---|---|
.Values | Merged values |
.Release | Name, Namespace, Revision, IsInstall, IsUpgrade |
.Chart | Chart.yaml fields, capitalised: .Chart.AppVersion |
.Capabilities | Cluster version and API versions |
.Template | Name and BasePath of the current file |
The checksum line: a Deployment does not restart when only its ConfigMap changes. Hashing the rendered ConfigMap into a Pod annotation changes the Pod template, so config changes roll the Pods.
Helpers and include
define names a snippet, include returns it as a string that can be piped. Use include, not template, because template cannot be piped into nindent.
Two rules: prefix helper names with the chart name, because helpers are global across subcharts. Keep changing values (version, chart) out of selectorLabels: selectors are immutable.
if, with, range
| Action | Does | Watch for |
|---|---|---|
if | Renders the block when the value is truthy | 0, "", false, empty map and list are all false |
with | Same test, and moves the dot to the value | The dot no longer has .Release |
range | Loops over a list or map | The dot is the item. Map keys come out sorted. |
Inside with and range the dot has moved. $ always points at the root.
Fix: write {{ $.Release.Name }}. With that change the same command printed release: bank-api.
default, required, quote, toYaml
| Function | Example from the chart | Why |
|---|---|---|
default | .Values.image.tag | default .Chart.AppVersion | Fallback when empty |
required | required "database.host is required" .Values.database.host | Stop the render with a clear message |
quote | {{ $value | quote }} | Keep 50000, true, no as strings |
toYaml | toYaml . | nindent 12 | Pass a whole map through unchanged |
nindent N | include "..." . | nindent 4 | New line, then indent every line by N |
Rendering without a database host stops here. The error names the Deployment because its checksum line includes the ConfigMap.
Schema: a values.schema.json beside values.yaml is checked at the same point. In a run with one added, --set replicaCount=0 failed with at '/replicaCount': minimum: got 0, want 1.
Trap: default treats false and 0 as empty, so .Values.enabled | default true can never be switched off. Put the default in values.yaml instead.
The whitespace trap
Template language · three real renders of the same block
An action leaves its own line behind. {{- eats whitespace and newlines to its left, -}} to its right. One dash too many joins two lines: with --debug, variant C showed daily: 50000vip: 200000.
The second trap is silent. Here the labels in service.yaml use plain include instead of include ... | nindent 4, so only the first line is indented.
Lesson: this is valid YAML, so helm template and helm lint both passed. Three labels became unknown top-level fields. Helm checks YAML, not Kubernetes schemas: see the checks.
Values and checks
Part 3 of 6 · one chart, two environments, no cluster needed
Dev and prod values files
An environment file holds only what differs from the defaults. The real diff of the two renders is the whole difference between dev and prod.
Values precedence
Later wins. Maps are merged key by key, lists are replaced whole.
| Flag | Use |
|---|---|
-f file.yaml | The normal way. Reviewed, in Git. |
--set a.b=1 | One value from CI, usually the image tag. Guesses the type: 1 is a number. |
--set-string | Force a string |
--set-file key=path | Value is the content of a file |
--set-json | A list or map in one flag |
On upgrade: values are not remembered by default. An upgrade uses the chart defaults plus what you pass this time. --reuse-values starts from the last release's values instead, and then misses new chart defaults. Passing the full -f files every time avoids both surprises.
helm template
Renders to stdout and touches nothing. The first argument is the release name. The ConfigMap shows required, range and quote at work.
| Flag | Use |
|---|---|
-s templates/x.yaml | Show only that template |
--debug | Print the output even when it is invalid YAML |
--kube-version, --api-versions | Fake .Capabilities, since no cluster is asked |
--output-dir | Write files, for GitOps tools that want plain YAML |
Lint, dry run, diff
Values and checks · only the first two rows of the table were run for this page
Limits seen in these runs: without a values file, lint reported the missing required value as [INFO] and still exited 0, also with --strict. It also passed the mis-indented Service. Lint once per environment file, and do not treat a pass as proof.
| Check | Cluster | Catches |
|---|---|---|
helm lint | No | Chart structure, YAML syntax, schema |
helm template | No | Template errors, required, schema |
| A schema validator on the rendered YAML, for example kubeconform | No | Unknown or misplaced fields |
helm upgrade --install --dry-run | No (client mode) | Same render, plus NOTES.txt |
--dry-run=server | Yes | Also resolves lookup and real capabilities |
helm template --validate | Yes | Manifests against the cluster's API |
helm diff upgrade (plugin) | Yes | What would change against the current release |
Careful: a dry run prints rendered Secrets. Helm has --hide-secret for that.
Releases and revisions
Part 4 of 6 · needs a cluster, so nothing in this part was run
Install and upgrade
Releases · Not run for this page
One idempotent command covers both, which is what CI wants.
--wait. Without it Helm marks the release deployed as soon as the API accepts the objects.| Flag | Effect |
|---|---|
--wait | Succeed only when Pods and Services are ready, within --timeout (default 5m) |
--atomic | --wait, and roll back automatically on failure |
--cleanup-on-fail | Delete objects that this failed upgrade created |
--history-max | Revisions kept per release (default 10) |
Versions: flags are from the Helm 3.22 help text. Helm 4 renames some of them (for example --atomic), so check the docs for the version you run.
History and rollback
Releases · Not run for this page
A rollback does not rewind. It re-applies an old revision's manifest as a new revision.
deployed at a time.Not rolled back: the database. If revision 3 ran a migration, revision 2's code now meets revision 3's schema. Keep migrations backward compatible for one release.
Where release state lives
Releases · Not run for this page
There is no Helm server and no local state file. Each revision is one Secret in the release's namespace.
sh.helm.release.v1.NAME.vN.| Consequence | Detail |
|---|---|
| Values are readable | Base64 and gzip, not encryption: see secrets |
| Size limit | A Secret holds about 1 MiB. Huge charts hit it. |
| Other backends | HELM_DRIVER: secret (default), configmap, sql, memory |
Beyond one chart
Part 5 of 6 · subcharts, hooks, secrets, distribution
Dependencies and subcharts
Beyond one chart · real run, with a tiny local cache chart (one Redis Deployment)
A dependency is another chart rendered into the same release. For this chapter these lines were added to a copy of the chart.
global.| Fact | Detail |
|---|---|
Subchart default 128mb became 64mb | Parent values override subchart defaults |
Chart.lock | Pins exact versions. Commit it. helm dependency build restores from it. |
| Before the update | Render failed: "found in Chart.yaml, but missing in charts/ directory: cache" |
condition | A values path that switches the subchart off |
Judgement: a database as a subchart shares the app's lifecycle, including uninstall. For stateful production systems prefer a separate release or a managed service.
Hooks
Beyond one chart · template rendered for real, hook execution not run
A hook is an ordinary manifest with an annotation that makes Helm run it at a point in the release lifecycle and wait for it.
| Annotation | Values |
|---|---|
helm.sh/hook | pre-install, post-install, pre-upgrade, post-upgrade, pre-rollback, post-rollback, pre-delete, post-delete, test |
helm.sh/hook-weight | A string number. Lower runs first. |
helm.sh/hook-delete-policy | before-hook-creation (default), hook-succeeded, hook-failed |
Traps: a pre-install hook runs before the chart's ConfigMap exists, which is why this Job takes DB_HOST directly. Hook objects are not part of the release, so helm uninstall does not remove them and a rollback does not undo them. Migrations must be safe to run twice.
Secrets
Beyond one chart · Not run for this page
Anything passed as a value is stored in the release Secret and shown by helm get values. So the chart here takes only a name, database.existingSecret, never the password.
| Option | How it works | Cost |
|---|---|---|
| Plain values in Git | Password in values-prod.yaml | Never do this |
--set from CI secrets | CI injects at deploy time | Still lands in the release Secret and maybe in logs |
| Encrypted values file (SOPS with the helm-secrets plugin) | Encrypted in Git, decrypted at deploy | Key management, and the release Secret still holds plaintext |
| Sealed Secrets | Encrypted object in Git, a controller decrypts in cluster | One more controller, tied to a cluster key |
| External Secrets Operator or the Secrets Store CSI driver | Chart ships a reference, the cluster fetches from a secret manager | An operator to run. Usually the best fit. |
Chart repos and OCI registries
Beyond one chart · helm package was run, the rest was not
Operating Helm
Part 6 of 6 · choosing it, fixing it, remembering it
Helm vs Kustomize
| Helm | Kustomize | |
|---|---|---|
| Model | Templates filled from values | Plain YAML base, patched by overlays |
| Files are valid YAML | No, until rendered | Yes, always |
| Logic | Conditions, loops, functions | None, by design |
| What can vary | Only what the chart author exposed | Any field, without asking the author |
| Release tracking, rollback | Yes | No: it only produces YAML |
| Hooks, ordering | Yes | No |
| Packaging and versioning | Charts in repos and registries | Git paths |
| Fits best | Software shipped to others, many knobs | Your own services, few differences per environment |
Both: they combine. Render a third-party chart with Helm, then patch the output with Kustomize. GitOps tools such as Argo CD and Flux support each and the combination.
Stuck in pending-upgrade
Operating Helm · Not run for this page
Helm writes pending-upgrade before it starts and the final status at the end. If the process dies in between (CI job cancelled, runner killed), the lock stays.
Prevent: --atomic with a --timeout shorter than the CI job's, and one deploy at a time per release (a CI concurrency group).
Field is immutable
Operating Helm · Not run for this page
Some fields cannot be patched after creation, and Helm only patches.
| Object | Immutable part | Usual cause in a chart |
|---|---|---|
| Deployment, StatefulSet | spec.selector | A version or chart label inside the selector labels |
| StatefulSet | volumeClaimTemplates | Changing storage size in values |
| Job | spec.template | A Job with a fixed name and a new image |
Fix: delete that one object and upgrade again (for a Deployment that means downtime unless you plan it), or give it a new name. For Jobs, make them hooks with a delete policy, as above. --force replaces objects and is rarely what you want in production.
Drift from manual edits
Operating Helm · behaviour as documented for Helm 3, not run for this page
Someone runs kubectl edit during an incident. Helm does not notice, and its three-way merge decides what happens to the edit on the next upgrade or rollback.
| Manual change with kubectl | On the next upgrade |
|---|---|
| Changed a field the chart sets (replicas, image) | Reset to the chart's value |
| Added a field the chart does not set (an annotation, an injected sidecar) | Kept, and Helm never mentions it |
| Deleted an object | Created again |
Rules: after a manual fix, put the same change in the values file and deploy it. helm diff compares with the stored manifest by default, not the live object, so it can show nothing while the cluster differs. If an HPA owns the replica count, leave replicas out of the template. Helm 4 can use server-side apply instead of this merge: check the docs.
Cheat sheet
| I want to | Command or rule |
|---|---|
| See the YAML without a cluster | helm template NAME CHART -f values.yaml |
| Deploy from CI | helm upgrade --install ... --atomic --timeout 5m |
| See what was passed and sent | helm get values NAME, helm get manifest NAME |
| Go back | helm history NAME, helm rollback NAME REV |
| Preview a change | helm diff upgrade (plugin) |
| Insert a block of YAML | {{- toYaml .Values.x | nindent N }} |
Reach the root inside with or range | $.Values, $.Release |
| Make a value mandatory | required "message" .Values.x, or a schema |
| Restart Pods on config change | checksum/config annotation |
| Override order | Defaults, then -f left to right, then --set |
| Fetch subcharts | helm dependency update, commit Chart.lock |
| Publish | helm package, helm push ... oci://... |
| Clear a stuck release | Roll back to the last deployed revision |
Interview questions
| Question | Short answer |
|---|---|
What does Helm add over kubectl apply? | Templating, a release as one unit, stored revisions with rollback, packaging. |
| Where does Helm 3 keep state? | One Secret per revision in the release namespace. No server component; Tiller was removed in Helm 3. |
| How are values merged? | Chart defaults, then each -f in order, then --set. Maps merge, lists are replaced. |
| How does a rollback work? | It applies an old revision's manifest as a new revision. It does not undo hooks or data changes. |
| What is the three-way merge? | The patch is built from the old manifest, the new manifest and the live object, so fields Helm never set survive. |
| A ConfigMap changed but Pods did not restart. Why? | The Pod template did not change. Add a checksum of the ConfigMap as a Pod annotation. |
| How do you run migrations? | A pre-upgrade hook Job, idempotent and backward compatible, because a rollback will not reverse it. |
| Where do secrets go? | Not in values: they end up readable in the release Secret. Reference an existing Secret filled by an operator. |
| "Another operation is in progress"? | A Helm process died mid-upgrade. Check nothing is running, then roll back to the last deployed revision. |
| Helm or Kustomize? | Helm for packaged software with many options and for rollback. Kustomize for small, readable per-environment patches. Often both. |
Back to Cloud and DevOps.