Helm Cheat Sheet
Reference for Helm chart structure, templating syntax, values files, and helm CLI commands for packaging Kubernetes applications.
Chart Structure
Standard directory layout of a Helm chart.
mychart/ Chart.yaml # Chart metadata (name, version) values.yaml # Default configuration values charts/ # Subcharts/dependencies templates/ deployment.yaml service.yaml _helpers.tpl # Reusable template partials .helmignore
Deployment Template
A templated Deployment manifest referencing values.
apiVersion: apps/v1kind: Deploymentmetadata: name: {{ .Release.Name }}-appspec: replicas: {{ .Values.replicaCount }} selector: matchLabels: app: {{ .Chart.Name }} template: metadata: labels: app: {{ .Chart.Name }} spec: containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" ports: - containerPort: {{ .Values.service.port }}
Helm CLI
Common commands for managing releases.
helm create mychart # Scaffold a new charthelm install myrelease ./mychart # Install a chart as a releasehelm upgrade myrelease ./mychart # Upgrade an existing releasehelm upgrade --install myrelease ./mychart # Install or upgradehelm rollback myrelease 1 # Roll back to revision 1helm list # List releaseshelm uninstall myrelease # Remove a releasehelm template ./mychart # Render templates locallyhelm lint ./mychart # Validate chart syntax
Key Concepts
Core Helm terminology.
- chart- A package of pre-configured Kubernetes resource templates
- release- A running instance of a chart installed into a cluster
- values.yaml- Default configuration values injected into templates
- repository- A collection of charts served over HTTP (helm repo add/update)
- hooks- Annotations that run jobs at specific points in a release lifecycle (pre-install, post-upgrade)
Named Templates in _helpers.tpl
Define reusable template partials with `define` and reference them with `include`.
{{- define "mychart.fullname" -}}{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" -}}{{- end -}}{{- define "mychart.labels" -}}app.kubernetes.io/name: {{ .Chart.Name }}app.kubernetes.io/instance: {{ .Release.Name }}app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}{{- end -}}# In deployment.yaml:metadata: name: {{ include "mychart.fullname" . }} labels: {{- include "mychart.labels" . | nindent 4 }}
Chart.yaml Dependencies
Declare subcharts with conditions, tags, and aliases for optional/renamed installs.
dependencies: - name: redis version: "18.x.x" repository: "https://charts.bitnami.com/bitnami" condition: redis.enabled tags: - caching - name: postgresql version: "13.x.x" repository: "https://charts.bitnami.com/bitnami" alias: primary-db condition: postgresql.enabled# After editing Chart.yaml:# helm dependency update ./mychart -- fetch and lock into charts/# helm dependency build ./mychart -- rebuild from Chart.lock
Template Functions & Pipelines
required, default, toYaml/nindent, tpl, and range for safer, DRY-er templates.
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"{{- $repo := required "image.repository must be set" .Values.image.repository }}resources: {{- toYaml .Values.resources | nindent 2 }}configMapData: | {{- tpl .Values.configTemplate . | nindent 2 }}env: {{- range $key, $value := .Values.env }} - name: {{ $key }} value: {{ $value | quote }} {{- end }}
Release Hook Lifecycle
Annotations that control when and how hook resources run and are cleaned up.
- helm.sh/hook- Attaches a resource to a lifecycle point: pre-install, post-install, pre-upgrade, post-upgrade, pre-delete, post-delete, test
- helm.sh/hook-weight- Integer controlling execution order among hooks at the same point; lower runs first
- helm.sh/hook-delete-policy- Controls cleanup: before-hook-creation (default), hook-succeeded, hook-failed
- helm.sh/resource-policy: keep- Prevents a resource (e.g. a PVC) from being deleted on `helm uninstall`
- helm test- Runs resources annotated with `helm.sh/hook: test` against a live release to verify it works
values.schema.json Validation
JSON Schema enforced automatically by helm install/upgrade/lint against values.yaml.
{ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": ["image", "replicaCount"], "properties": { "replicaCount": { "type": "integer", "minimum": 1 }, "image": { "type": "object", "required": ["repository"], "properties": { "repository": { "type": "string" }, "tag": { "type": "string" } } } }}
Run 'helm template' before 'helm install' to render manifests locally and catch templating errors, since Helm's error messages for broken Go template syntax are often unclear at install time.