Helm charts
Package your manifests into a chart with per-environment values.
By Invicly Tech, , in Full DevOps with Python. About 13 minutes to read.
In short
Helm packages Kubernetes manifests into a chart with templates and values. One chart installs the same app into dev and prod with different settings, and every upgrade can be rolled back.
Explained simply
After a while, your Kubernetes YAML files repeat themselves. Dev and prod need the same Deployment, Service and Ingress, but with a different image tag, replica count and host name. Copying the files and editing them by hand leads to mistakes. Helm fixes this.
Helm is a package manager for Kubernetes. A package is called a chart: a folder of YAML templates with blanks in them, plus a values file that fills in the blanks. You install the same chart many times with different values.
Each installed copy of a chart is a release, with a name like api. Every time you upgrade it, Helm saves a new numbered revision. If version 5 is broken, you can tell Helm to go back to version 4 with one command.
Helm also lets you install software other people packaged, such as Prometheus, Grafana or PostgreSQL, from public chart repositories. You only change the values you care about instead of writing hundreds of lines of YAML.
Press Play on a diagram to walk through it one step at a time.
- Chart.yaml
- Name, version, appVersion
- values.yaml
- Default settings
- image.tag, replicas
- values-prod.yaml
- Overrides for production
- templates/
- deployment.yaml
- service.yaml
- ingress.yaml
- _helpers.tpl
- Step 1helm install
Creates release revision 1.
- Step 2helm upgrade
New values or image tag, revision 2.
- Step 3helm history
Lists every revision and its status.
- Step 4helm rollback
Returns to a previous good revision.
- Copy YAML per environment
- No templating to learn
- Drift and copy mistakes grow
- No release history
- Templates plus values files
- Release revisions and rollback
- Share and install public charts
- Templates can get complex
- Base YAML plus patches
- No templates, built into kubectl -k
- No release history or rollback
- Good for small differences
- CI job to Helm CLI: upgrade --install api --set image.tag=sha1upgrade --install api --set image.tag=sha
- Helm CLI to Release Secret: Read the last revision2Read the last revision
- 3Render templates with merged valuesHelm CLI to Helm CLI: Render templates with merged values
- Helm CLI to API server: Patch Deployment, Service, Ingress4Patch Deployment, Service, Ingress
- Helm CLI to API server: Wait until Pods are ready5Wait until Pods are ready
- Helm CLI to Release Secret: Save new revision as deployed6Save new revision as deployed
- Helm CLI to CI job: Exit 0, deploy done7Exit 0, deploy done
In depth
How Helm renders a chart
Helm templates use the Go template language plus extra functions from the Sprig library. Anything between double curly braces is evaluated. Helm gives every template a few built-in objects: .Values (the merged values), .Release (the release name, namespace and revision), .Chart (the fields of Chart.yaml) and .Capabilities (what the cluster's API supports).
Common functions do most of the work. default gives a fallback value, quote wraps a value in quotes, required stops rendering with your error message if a value is missing, and toYaml turns a whole map, like resources, into YAML. Because YAML depends on indentation, toYaml is usually piped into nindent, which adds a newline and indents the block by a given number of spaces.
Files in templates/ whose names start with an underscore, like _helpers.tpl, produce no output. They hold named templates created with define and used with include, typically for the chart's standard labels and names. After rendering, Helm sorts the objects by kind (for example Namespaces before Deployments) and sends them to the API server.
- 1Merge values
values.yaml, -f files, then --set
- 2Render templates
Go templates fill in the blanks
- 3Plain YAML
What helm template prints
- 4Send to API
Create or patch each object
- 5Save revision
Release record stored in a Secret
Values and their order of precedence
Values can come from several places, and Helm merges them in a fixed order where later sources win. First come the chart's own values.yaml defaults. Then each file you pass with -f (or --values), in the order you pass them. Last come --set flags on the command line. So helm upgrade api ./api -f values.yaml -f values-prod.yaml --set image.tag=1.4.1 uses prod overrides on top of the defaults, and the tag from the command line on top of everything.
Maps are merged deeply: if values-prod.yaml sets only resources.limits.memory, the other keys under resources stay. Lists are not merged; a list in a later file replaces the whole earlier list. To delete a default key, set it to null.
A good pattern: keep values.yaml as safe, documented defaults, one small file per environment with only the differences, and use --set only for the value that changes on every deploy, usually the image tag from CI. A values.schema.json file in the chart can validate types and required fields before anything is rendered.
- 1--set image.tag=1.4.1
Command line, highest priority
- 2-f values-prod.yaml
Last -f file wins over earlier ones
- 3-f values-common.yaml
Shared overrides
- 4Chart values.yaml
Defaults shipped with the chart
Turning plain manifests into a chart
Start with helm create api, which scaffolds Chart.yaml, values.yaml and templates for a Deployment, Service, Ingress, ServiceAccount and more. Many people delete most of the scaffold and copy in their own working manifests instead, then template them step by step.
Go through each manifest and replace only what really differs between installs: image repository and tag, replicas, resources, host names, and environment settings. Leave everything else as plain YAML; a chart where every line is a value is hard to read. Use the release name in object names (often through the fullname helper) so two installs in one namespace do not collide, and add the recommended labels app.kubernetes.io/name and app.kubernetes.io/instance from a helper.
In Chart.yaml, version is the chart's own version and must follow semver; appVersion is the version of the app inside, used for information and often as the default image tag. Check your work with helm lint, then helm template to read the output, then helm install with --dry-run to let the server validate it too.
- helm lint ./api catches template and YAML errors
- helm template api ./api -f values-prod.yaml shows the final YAML
- Bump version in Chart.yaml whenever the chart itself changes
Releases, revisions and safe upgrades
Helm 3 has no server-side component. It stores each revision of a release as a Secret in the release's namespace, named like sh.helm.release.v1.api.v3, holding the rendered manifest and the values used. helm list -n prod and helm history read these Secrets. By default Helm keeps the last 10 revisions per release on upgrade (--history-max).
helm upgrade --install is the usual command in pipelines because it installs the release if it does not exist and upgrades it if it does. Add --wait so Helm waits until Deployments are ready, and --timeout to set how long. In Helm 3, --atomic also rolls back automatically if the upgrade fails, so a broken release never stays in place.
A rollback does not delete history. helm rollback api 3 creates a new revision, for example 6, whose content equals revision 3. Helm compares the old manifest, the new one and the live objects when it patches, so manual kubectl changes to fields the chart manages may be overwritten on the next upgrade.
Dependencies, OCI registries and secrets
A chart can depend on other charts. You list them under dependencies in Chart.yaml with a name, version range and repository, then helm dependency update downloads them into the charts/ folder. Values for a dependency go under its name in your values file, for example redis.auth.enabled.
Charts can be shared through classic chart repositories (helm repo add, then helm install bitnami/postgresql) or through OCI registries, the same registries that store container images, such as GHCR, ECR or Docker Hub. helm package ./api creates a .tgz file, helm push sends it to an oci:// address, and helm install can install straight from that address.
Never put real passwords in values files committed to Git: the rendered values are also stored in the release Secret, readable by anyone who can read Secrets in that namespace. Common options are creating the Kubernetes Secret outside Helm (from CI or External Secrets Operator) and only referencing its name in the chart, or encrypting values files with SOPS and the helm-secrets plugin.
Learn it in 4 short steps
About 1h each. Track them with a timer in your plan.
- 1Learn chart structure and templates~1h
- 2Convert manifests into a chart~1h
- 3Add per-environment values files~1h
- 4Install, upgrade and roll back releases~1h
Key points
- Templates use {{ .Values.x }} so one chart serves many environments.
- Pass environment overrides with -f values-prod.yaml or --set.
- helm template renders manifests locally so you can review them first.
- Each upgrade is a numbered revision you can roll back to.
Key terms
Tap a card to flip it. 0/4 known
Examples
helm create api
helm template api ./api -f api/values-prod.yaml | less
helm install api ./api -n prod --create-namespace -f api/values-prod.yaml
helm upgrade api ./api -n prod -f api/values-prod.yaml --set image.tag=1.4.1
helm history api -n prod
helm rollback api 1 -n prodRender, install, upgrade and roll back a release.
Template the Deployment image, replicas and resources
Step 1: in values.yaml set replicaCount: 2, image.repository: ghcr.io/acme/api, image.tag empty, and resources with requests and limits. Step 2: in templates/deployment.yaml, use the fullname helper for the name and the labels helper for labels. Step 3: the tag falls back to the chart's appVersion when it is not set. Step 4: resources is a whole map, so toYaml plus nindent writes it with the right indentation. Step 5: run helm template and read the result before installing.
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "api.fullname" . }}
labels: {{- include "api.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector: { matchLabels: { app.kubernetes.io/instance: {{ .Release.Name }} } }
template:
metadata: { labels: { app.kubernetes.io/instance: {{ .Release.Name }} } }
spec:
containers:
- name: api
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
resources: {{- toYaml .Values.resources | nindent 12 }}A bad upgrade in prod and a quick rollback
Step 1: CI deploys image 1.5.0 with --wait and a 5 minute timeout. Step 2: the new Pods fail readiness, so Helm times out and marks revision 4 as failed. Step 3: helm history shows revision 3 as the last good one. Step 4: helm get values for revision 3 confirms what it ran with. Step 5: roll back to 3, which creates revision 5 with the same content. Step 6: fix the bug and deploy 1.5.1 normally.
helm upgrade --install api ./charts/api -n prod \
-f charts/api/values-prod.yaml --set image.tag=1.5.0 --wait --timeout 5m
# Error: UPGRADE FAILED: context deadline exceeded
helm history api -n prod # 3 superseded, 4 failed
helm get values api -n prod --revision 3
helm rollback api 3 -n prod --wait
helm history api -n prod # 5 deployed: Rollback to 3
kubectl get pods -n prod -l app.kubernetes.io/instance=apiQuick reference
- helm upgrade --install name chart -n ns --create-namespace installs or upgrades in one command
- helm template name ./chart -f values-prod.yaml renders YAML locally without a cluster
- helm get values name -n ns shows the values a release is using now
- helm get manifest name -n ns shows the YAML Helm applied
- Later -f files override earlier ones, and --set overrides all files
- helm list -A lists every release in every namespace
- helm uninstall name -n ns removes the release and its objects
- helm show values repo/chart prints a public chart's default values
Common mistakes
- Editing resources with kubectl after Helm installs them, causing drift.
- Committing secrets in values.yaml in plain text.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Install the public Bitnami nginx chart in kind with 2 replicas, then list the release and its Pods.
- Exercise 2medium
Create a chart for your API with values-dev.yaml (1 replica, debug logs) and values-prod.yaml (3 replicas, info logs). Show that the rendered output differs.
- Exercise 3hard
Make the chart refuse to render without an image tag, and make Pods restart automatically when the ConfigMap template changes.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- What is the difference between Helm and Kustomize?
- Helm uses templates and values and tracks releases with rollback. Kustomize patches plain YAML without templates and is built into kubectl apply -k, but has no release history.
- What is the difference between version and appVersion in Chart.yaml?
- version is the chart package's own semver version, which you bump when the chart changes. appVersion is the version of the application it deploys and is informational.
- Does Helm still need Tiller?
- No. Tiller was removed in Helm 3; Helm now talks to the API server directly with your kubeconfig permissions.
- How do I see what an upgrade will change before running it?
- Run helm template or helm upgrade --dry-run to see the output, or install the helm-diff plugin and run helm diff upgrade to see a diff against the live release.