Learnings

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

Why Helm

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.

Copies drift because nothing forces a change through all of them.
PainWhat Helm gives
Same YAML copied per environmentOne template, one small values file each
Ten objects applied one by oneOne release, installed and removed as a unit
"What is deployed, and since when?"helm list, helm history
Rolling back by handhelm rollback to a stored revision
Installing other people's softwarePublished 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

Why Helm

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.

Rendering is local text processing. The cluster only ever sees plain manifests.
WordMeaning
ChartA folder (or .tgz) of templates and default values
ValuesThe inputs: defaults, then your overrides
ReleaseOne installed instance of a chart, with a name, in a namespace
RevisionA numbered snapshot of a release: 1 on install, +1 per upgrade or rollback
RepositoryWhere packaged charts are published

Chart layout

Why Helm · real listing of the chart used on this page

PathPurpose
Chart.yamlName, versions, dependencies
values.yamlDefaults, and the documentation of every knob
templates/*.yamlManifests with {{ }} actions
templates/_helpers.tplNamed snippets. Files starting with _ render no manifest.
templates/NOTES.txtText printed after install
charts/Subcharts, filled by helm dependency update
crds/CRDs: installed once, never templated, never upgraded
values.schema.jsonOptional 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

Template language

A template is YAML with holes. Each {{ }} reads from the dot, which at the top of a file holds these objects.

ObjectHolds
.ValuesMerged values
.ReleaseName, Namespace, Revision, IsInstall, IsUpgrade
.ChartChart.yaml fields, capitalised: .Chart.AppVersion
.CapabilitiesCluster version and API versions
.TemplateName 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

Template language

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.

One definition, used by every manifest. Names and labels cannot disagree.

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

Template language

ActionDoesWatch for
ifRenders the block when the value is truthy0, "", false, empty map and list are all false
withSame test, and moves the dot to the valueThe dot no longer has .Release
rangeLoops over a list or mapThe 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

Template language

FunctionExample from the chartWhy
default.Values.image.tag | default .Chart.AppVersionFallback when empty
requiredrequired "database.host is required" .Values.database.hostStop the render with a clear message
quote{{ $value | quote }}Keep 50000, true, no as strings
toYamltoYaml . | nindent 12Pass a whole map through unchanged
nindent Ninclude "..." . | nindent 4New 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

Values and checks

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

Values and checks

Later wins. Maps are merged key by key, lists are replaced whole.

Lowest priority at the top. The second step applies to subcharts only: the parent's values override a subchart's defaults.
FlagUse
-f file.yamlThe normal way. Reviewed, in Git.
--set a.b=1One value from CI, usually the image tag. Guesses the type: 1 is a number.
--set-stringForce a string
--set-file key=pathValue is the content of a file
--set-jsonA 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

Values and checks

Renders to stdout and touches nothing. The first argument is the release name. The ConfigMap shows required, range and quote at work.

FlagUse
-s templates/x.yamlShow only that template
--debugPrint the output even when it is invalid YAML
--kube-version, --api-versionsFake .Capabilities, since no cluster is asked
--output-dirWrite 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.

CheckClusterCatches
helm lintNoChart structure, YAML syntax, schema
helm templateNoTemplate errors, required, schema
A schema validator on the rendered YAML, for example kubeconformNoUnknown or misplaced fields
helm upgrade --install --dry-runNo (client mode)Same render, plus NOTES.txt
--dry-run=serverYesAlso resolves lookup and real capabilities
helm template --validateYesManifests against the cluster's API
helm diff upgrade (plugin)YesWhat 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.

An upgrade with --wait. Without it Helm marks the release deployed as soon as the API accepts the objects.
FlagEffect
--waitSucceed only when Pods and Services are ready, within --timeout (default 5m)
--atomic--wait, and roll back automatically on failure
--cleanup-on-failDelete objects that this failed upgrade created
--history-maxRevisions 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.

Statuses of one revision. Only one revision of a release is 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.

One Secret per revision, named sh.helm.release.v1.NAME.vN.
ConsequenceDetail
Values are readableBase64 and gzip, not encryption: see secrets
Size limitA Secret holds about 1 MiB. Huge charts hit it.
Other backendsHELM_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.

Values flow down only. A subchart cannot see its parent's values, except global.
FactDetail
Subchart default 128mb became 64mbParent values override subchart defaults
Chart.lockPins exact versions. Commit it. helm dependency build restores from it.
Before the updateRender failed: "found in Chart.yaml, but missing in charts/ directory: cache"
conditionA 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.

The Deployment is only touched after the migration Job completes.
AnnotationValues
helm.sh/hookpre-install, post-install, pre-upgrade, post-upgrade, pre-rollback, post-rollback, pre-delete, post-delete, test
helm.sh/hook-weightA string number. Lower runs first.
helm.sh/hook-delete-policybefore-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.

The chart references the Secret. Something else owns its content.
OptionHow it worksCost
Plain values in GitPassword in values-prod.yamlNever do this
--set from CI secretsCI injects at deploy timeStill lands in the release Secret and maybe in logs
Encrypted values file (SOPS with the helm-secrets plugin)Encrypted in Git, decrypted at deployKey management, and the release Secret still holds plaintext
Sealed SecretsEncrypted object in Git, a controller decrypts in clusterOne more controller, tied to a cluster key
External Secrets Operator or the Secrets Store CSI driverChart ships a reference, the cluster fetches from a secret managerAn operator to run. Usually the best fit.

Chart repos and OCI registries

Beyond one chart · helm package was run, the rest was not

Build the chart once, promote the same version through environments, like an image.

Operating Helm

Part 6 of 6 · choosing it, fixing it, remembering it

Helm vs Kustomize

Operating Helm

HelmKustomize
ModelTemplates filled from valuesPlain YAML base, patched by overlays
Files are valid YAMLNo, until renderedYes, always
LogicConditions, loops, functionsNone, by design
What can varyOnly what the chart author exposedAny field, without asking the author
Release tracking, rollbackYesNo: it only produces YAML
Hooks, orderingYesNo
Packaging and versioningCharts in repos and registriesGit paths
Fits bestSoftware shipped to others, many knobsYour 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.

Check for a live Helm process first. Two concurrent upgrades are worse than a stuck one.

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.

ObjectImmutable partUsual cause in a chart
Deployment, StatefulSetspec.selectorA version or chart label inside the selector labels
StatefulSetvolumeClaimTemplatesChanging storage size in values
Jobspec.templateA 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.

Old and new come from the release Secrets. Live comes from the API server.
Manual change with kubectlOn 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 objectCreated 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

Operating Helm

I want toCommand or rule
See the YAML without a clusterhelm template NAME CHART -f values.yaml
Deploy from CIhelm upgrade --install ... --atomic --timeout 5m
See what was passed and senthelm get values NAME, helm get manifest NAME
Go backhelm history NAME, helm rollback NAME REV
Preview a changehelm 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 mandatoryrequired "message" .Values.x, or a schema
Restart Pods on config changechecksum/config annotation
Override orderDefaults, then -f left to right, then --set
Fetch subchartshelm dependency update, commit Chart.lock
Publishhelm package, helm push ... oci://...
Clear a stuck releaseRoll back to the last deployed revision

Interview questions

Operating Helm

QuestionShort 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.