Skip to content

Helm Intermediate Guide

Move beyond the basics and master the power of Helm's templating engine.

๐Ÿ“ Templating Engine

Helm uses the Go Template language. Templates are located in the templates/ directory and are combined with values.yaml to generate valid Kubernetes manifests.

The Scope (.)

The dot . represents the current context. In the top scope, it contains: * .Values (from values.yaml) * .Release (Name, Namespace, Service) * .Chart (Metadata from Chart.yaml) * .Capabilities (Kubernetes cluster versions)

apiVersion: v1
kind: Pod
metadata:
  name: {{ .Release.Name }}-app

๐Ÿ”„ Flow Control

If / Else

Control what gets rendered based on values.

{{- if .Values.ingress.enabled }}
kind: Ingress
metadata:
  name: example
{{- else }}
# Ingress is disabled
{{- end }}
Note: The - trims whitespace (newlines) before or after the bracket.

With

Changes the scope (.) to a specific object to avoid repetition.

{{- with .Values.image }}
image: {{ .repository }}:{{ .tag }}
{{- end }}

Range (Loops)

Iterate over lists or maps.

env:
{{- range .Values.env }}
  - name: {{ .name }}
    value: {{ .value }}
{{- end }}

โš“ Helm Hooks

Hooks allow you to intervene at specific points in a release's life cycle. Common use cases include: * pre-install/post-install: Run database migrations or seed data. * pre-delete: Clean up external resources.

Define a hook using an annotation:

apiVersion: batch/v1
kind: Job
metadata:
  name: "{{ .Release.Name }}-migrate"
  annotations:
    "helm.sh/hook": pre-install,pre-upgrade
    "helm.sh/hook-delete-policy": hook-succeeded

๐Ÿ› ๏ธ Debugging Templates

Dry Run

Simulate an install and check for validation errors.

helm install myapp . --dry-run

Template Render

Print the raw generated YAML to stdout (useful for inspecting logic).

helm template myapp .
With debug info:
helm template myapp . --debug

๐Ÿ“ฆ Named Templates (_helpers.tpl)

To reuse logic (like standard labels), define named templates in a file starting with _ (usually _helpers.tpl).

Definition:

{{/* _helpers.tpl */}}
{{- define "mychart.labels" -}}
app: {{ .Chart.Name }}
version: {{ .Chart.Version }}
managed-by: {{ .Release.Service }}
{{- end }}

Usage:

metadata:
  labels:
    {{- include "mychart.labels" . | nindent 4 }}


๐Ÿง  Quick Quiz

#

What templating engine does Helm use?

๐Ÿ‘‰ Take the Helm Intermediate Quiz


๐Ÿ“ฌ DevopsPilot Weekly โ€” Learn DevOps, Cloud & Gen AI the simple way.
๐Ÿ‘‰ Subscribe here