๐ What is Helm?
Helm is a package manager for Kubernetes. It helps you define, install, and manage Kubernetes applications using Helm charts, which are collections of Kubernetes manifests combined into a single package.
๐งฑ Helm Chart Structure
When you create a new chart with helm create mychart, this is the typical directory structure:
mychart/
โโโ .helmignore
โโโ Chart.yaml
โโโ values.yaml
โโโ charts/
โโโ templates/
โ โโโ deployment.yaml
โ โโโ service.yaml
โ โโโ ingress.yaml
โ โโโ _helpers.tpl
โ โโโ ...
๐น 1. Chart.yaml
Metadata about your chart.
apiVersion: v2
name: mychart
description: "A Helm chart for Kubernetes"
type: application
version: 0.1.0
appVersion: 1.16.0
๐น 2. values.yaml
Default values for your templates.
replicaCount: 2
image:
repository: nginx
tag: stable
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
๐น 3. templates/
YAML templates that generate Kubernetes manifests.
๐ Step-by-Step: Creating a Helm Chart
โ Step 1: Install Helm
brew install helm # macOS
choco install kubernetes-helm # Windows
โ Step 2: Create a New Chart
helm create mychart
โ
Step 3: Modify Chart.yaml
Update the metadata.
โ
Step 4: Customize values.yaml
This allows configuration without changing the templates.
โ
Step 5: Write Templates (templates/)
Templates use Go templating:
Example: deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-deployment
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: 80
๐ก Helm Template Language Basics
-
{{ .Values.xxx }}: Access value fromvalues.yaml. -
{{ .Chart.Name }}: Chart metadata. -
{{ .Release.Name }}: Name of the release. -
{{- if ... }}/{{- else }}/{{- end }}: Control logic. -
{{ include "mychart.fullname" . }}: Use helper templates.
๐ฆ Packaging and Installing the Chart
โ Step 1: Lint the chart
helm lint mychart
โ Step 2: Package the chart
helm package mychart
This creates mychart-0.1.0.tgz.
โ Step 3: Install the chart
helm install myrelease ./mychart
โ Step 4: Upgrade the chart
helm upgrade myrelease ./mychart
โ Step 5: Uninstall the chart
helm uninstall myrelease
๐ง Overriding Values
helm install myrelease ./mychart --set replicaCount=3
Or with a file:
helm install myrelease ./mychart -f myvalues.yaml
๐ง Advanced Concepts
โ
1. dependencies and charts/
Declare dependencies in Chart.yaml:
dependencies:
- name: redis
version: 14.8.8
repository: https://charts.bitnami.com/bitnami
Then run:
helm dependency update
โ
2. helpers.tpl
Reusable functions:
{{- define "mychart.fullname" -}}
{{ printf "%s-%s" .Release.Name .Chart.Name }}
{{- end }}
Use like:
metadata:
name: {{ include "mychart.fullname" . }}
โ 3. Conditional Resources
{{- if .Values.service.enabled }}
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
...
{{- end }}
๐ Helm Repositories
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm search repo nginx
helm install my-nginx bitnami/nginx
๐งช Helm Testing
In templates/tests/test-connection.yaml:
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "mychart.fullname" . }}-test"
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "mychart.fullname" . }}']
restartPolicy: Never
Run tests:
helm test myrelease
๐ค Helm Chart Best Practices
- Use
values.yamlfor all configurable settings. - Use
_helpers.tplto keep templates DRY. - Always run
helm lint. - Include tests and probes (liveness/readiness).
- Use semantic versioning.
- Document values in
README.md.
๐ณ Dockerize Your Helm App (Optional)
For CI/CD, create a Dockerfile that copies your Helm chart into an image, or run Helm from a pipeline.
๐ Helm in Production
- Use
helm diffto preview changes. - Use Helm secrets or external secret managers for sensitive data.
- Store Helm charts in private registries (e.g., Harbor, ChartMuseum, OCI registries).
- Automate deployments with ArgoCD or Flux.
๐ Bonus: Useful Commands
helm list # List all releases
helm uninstall myrelease # Delete release
helm get manifest myrelease # Show rendered YAML
helm template mychart # Render templates locally
helm show values mychart # Show default values
helm show chart mychart # Show chart metadata
Top comments (0)