Helm Templates: Turning Static YAML into Dynamic Manifests
Think of Helm templating as a mail merge for Kubernetes. It combines static YAML templates with dynamic values to generate manifests for different environments. Use it to manage configurations for dev, staging, and prod.
WHY IT EXISTS: Managing raw Kubernetes YAML is repetitive and error-prone. You often end up with nearly identical files for development, staging, and production, differing only by a few values like image tags or replica counts. Helm templating was created to solve this duplication by letting you define an application's structure once and inject configuration at deployment time.
THE MENTAL MODEL: Helm templating is a "mail merge" for Kubernetes. You have a template file (the letter, which is your Kubernetes YAML with placeholders) and a values file (the address book, containing your environment-specific settings). Helm's template engine reads both, substitutes the placeholders with the correct values, and generates the final, valid Kubernetes manifest files that kubectl can apply.
HOW IT WORKS: Helm uses the Go template language. Inside a chart's templates/ directory, you write standard Kubernetes YAML files but with special syntax. Placeholders like {{ .Values.replicaCount }} are used to reference data from values.yaml files. Helm provides built-in objects (like .Release and .Chart), over 60 functions, and control structures like if/else blocks and range loops to build dynamic manifests. A critical detail is managing YAML indentation; since the template engine is unaware of YAML's structure, you must use functions like nindent to ensure the rendered output is valid. The helm template or helm install command processes these templates, rendering them into plain YAML.
WHEN TO USE IT: Use Helm templating whenever you need to deploy the same application to multiple environments or with different configurations. It's the standard for packaging reusable applications for the Kubernetes community. It's ideal for managing complexity, such as conditionally creating resources or dynamically generating configuration based on a list of items.
WHEN NOT TO USE IT: For very simple, single-environment applications with no configurable parts, raw YAML might be simpler. If your team is not familiar with Go templating, the learning curve can be a barrier. For extremely complex logic, the template language can become hard to read and debug; tools like Kustomize might offer a more declarative alternative.
ONE CANONICAL EXAMPLE: A common pattern is setting the number of replicas for a Deployment. In your values.yaml, you define replicaCount: 3. In your templates/deployment.yaml, you write replicas: {{ .Values.replicaCount }}. When you run helm install, Helm replaces {{ .Values.replicaCount }} with 3. To deploy to a dev environment with only one replica, you can override this with --set replicaCount=1 without ever touching the template file itself.
Read the original → helm.sh
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.