Skip to content

Helm Development

Helm charts are a core tool for packaging and deploying Kubernetes applications, enabling declarative, versioned, and repeatable deployments. This section covers the principles and practices of Helm chart development, including chart structure, templating, and advanced customization techniques.


Core Concepts of Helm Charts

A Helm chart is a collection of files organized into directories that describe a Kubernetes application. Key components include:
- Chart.yaml: Metadata about the chart (name, version, description).
- values.yaml: Default configuration values for the application.
- templates/: Kubernetes manifest files (e.g., Deployments, Services) with templating logic.
- charts/: Subcharts (dependencies) for modularized applications.

Helm uses a templating engine to render manifests dynamically, replacing placeholders (e.g., {{ .Values.replicaCount }}) with actual values during deployment.


Creating a Helm Chart

Use the helm create command to scaffold a new chart:

helm create my-chart
This generates a directory structure like:
my-chart/
├── Chart.yaml
├── charts/
├── templates/
│   ├── deployment.yaml
│   ├── service.yaml
│   └── _helpers.tpl
└── values.yaml

Customizing Templates:
Modify templates/deployment.yaml to use values from values.yaml:

spec:
  replicas: {{ .Values.replicaCount }}
  containers:
  - name: app
    image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"

Best Practices:
- Keep templates minimal and focused on logic.
- Use values.yaml for configuration overrides.
- Leverage _helpers.tpl for reusable snippets.


Advanced Templating

Helm’s templating language supports conditionals, loops, and logic:

{{- if .Values.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-config
data:
  config: |
    {{ .Values.config }}
{{- end }}

Loops:

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

Use helm template to preview rendered manifests:

helm template my-chart . --set replicaCount=3


Managing Dependencies

Use charts/ directory to include subcharts (dependencies):

helm dependency add stable/mysql

Define dependencies in Chart.yaml:

dependencies:
  - name: mysql
    version: "1.5.0"
    repository: "https://charts.helm.sh/repo"

Update dependencies with helm dependency update and manage versions explicitly.


Testing and Debugging

Deploy a chart with:

helm install my-release ./my-chart

Test upgrades with:

helm upgrade my-release ./my-chart --set replicaCount=5

Rollback to a previous release:

helm rollback my-release 1

Debug templating issues using --dry-run:

helm install my-release ./my-chart --dry-run


Versioning and Packaging

Follow semantic versioning (e.g., 1.0.0) in Chart.yaml. Package the chart:

helm package my-chart
This generates my-chart-1.0.0.tgz.

Host charts in a repository using helm repo index:

helm repo index --url https://example.com/charts my-chart/


Key takeaways

  • Helm charts structure applications into reusable, versioned packages.
  • Templating enables dynamic configuration and conditional logic.
  • Dependencies simplify modular application design.
  • Testing and rollback ensure reliable deployments.
  • Proper versioning and packaging enable chart reuse and distribution.