← All writing

The Practical Guide to Helm: Charts, Templates & Avoiding YAML Spaghetti

· Sourabh G Kulkarni

Mastering Helm in enterprise Kubernetes: chart architecture, helper templates, release management, and when to choose Helm vs Kustomize.

The Practical Guide to Helm: Charts, Templates & Avoiding YAML Spaghetti

Writing plain Kubernetes YAML manifests works for a single environment. But when you need to deploy the same microservice across Development, Staging, and Multi-Region Production clusters with different CPU limits, domain names, and replica counts, maintaining separate copies of YAML becomes an unmanageable chore.

Helm is the package manager for Kubernetes. It turns static Kubernetes manifests into dynamic, parameterized templates driven by centralized values.yaml files.

flowchart LR
    Chart["Helm Chart (Template Engine)"]
    ValuesDev["values-dev.yaml (replicas: 1)"]
    ValuesProd["values-prod.yaml (replicas: 10)"]

    subgraph Engine["Helm CLI Engine (Go Templates)"]
        Render["helm template / upgrade --install"]
    end

    subgraph K8s["Kubernetes Cluster"]
        DevDeploy["Deployment (1 Pod)"]
        ProdDeploy["Deployment (10 Pods, HPA, PDB)"]
    end

    Chart --> Engine
    ValuesDev --> Engine
    ValuesProd --> Engine

    Engine -->|Deploy to Dev| DevDeploy
    Engine -->|Deploy to Prod| ProdDeploy

1. Anatomy of a Helm Chart

A well-structured Helm chart isolates configuration from manifest definitions:

my-app/
├── Chart.yaml          # Metadata (name, version, appVersion, dependencies)
├── values.yaml         # Default configuration values
├── templates/
│   ├── _helpers.tpl    # Named template snippets (labels, names)
│   ├── deployment.yaml # Kubernetes Deployment template
│   ├── service.yaml    # Kubernetes Service template
│   ├── hpa.yaml        # Autoscaling template
│   └── NOTES.txt       # Post-installation instructions printed to terminal
└── .helmignore         # Files to exclude during packaging

2. Dynamic Templating with Go Templates

Instead of hardcoding replica counts or image tags, reference values dynamically:

# templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "my-app.fullname" . }}
  labels:
    {{- include "my-app.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "my-app.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "my-app.selectorLabels" . | nindent 8 }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          resources:
            {{- toYaml .Values.resources | nindent 12 }}

The Clean Template Helper: _helpers.tpl

Avoid repeating standard labels across every template file. Centralize them in _helpers.tpl:

{{/* Standard Kubernetes labels */}}
{{- define "my-app.labels" -}}
helm.sh/chart: {{ include "my-app.chart" . }}
app.kubernetes.io/name: {{ include "my-app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

3. Safe Production Deployment Commands

Never run blind installs in production. Use dry-run and diff plugins first:

# 1. Lint chart syntax and conventions
helm lint ./my-app

# 2. Render templates locally to stdout to inspect the exact resulting YAML
helm template my-release ./my-app -f values-prod.yaml

# 3. Perform a dry-run against the live cluster
helm upgrade --install my-release ./my-app -f values-prod.yaml --dry-run

# 4. Execute atomic release (automatically rolls back if pods fail readiness probes within 5 min)
helm upgrade --install my-release ./my-app -f values-prod.yaml --atomic --timeout 5m

4. Helm vs. Kustomize: The Verdict

CriteriaHelmKustomize
PhilosophyParameterized templating ({{ .Values }})Pure overlay patches (no template variables)
Release TrackingTracks releases in cluster Secrets (helm history)Stateless (leaves tracking to Git)
Best ForThird-party shared packages (Ingress, Cert-Manager) & multi-tenant microservice templatesIn-house microservices where simple environment overlays suffice

By mastering Helm helpers, values separation, and --atomic safeguards, you package and deploy cloud-native applications with confidence across any cluster.