Helm is the package manager for Kubernetes, simplifying application deployment through reusable charts. It handles templating, versioning, and release management.
Why Helm?
flowchart LR
subgraph Without["Without Helm"]
A1["deployment.yaml"]
A2["service.yaml"]
A3["configmap.yaml"]
A4["secret.yaml"]
A5["ingress.yaml"]
end
subgraph With["With Helm"]
B["Single Chart"]
end
Without -->|"kubectl apply -f ..."| C["Manual Management"]
With -->|"helm install"| D["Automated Management"]
style Without fill:#ef4444,color:#fff
style With fill:#22c55e,color:#fff
Helm Concepts
| Concept |
Description |
| Chart |
Package of Kubernetes resources |
| Release |
Installed instance of a chart |
| Repository |
Collection of charts |
| Values |
Configuration for chart customization |
| Template |
Kubernetes manifests with placeholders |
Installing Helm
brew install helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
helm version
Working with Repositories
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm repo list
helm search repo nginx
helm search hub prometheus
Installing Charts
Basic Installation
helm install my-nginx bitnami/nginx
helm install my-nginx bitnami/nginx -n web --create-namespace
helm install my-nginx bitnami/nginx --set service.type=ClusterIP
helm install my-nginx bitnami/nginx -f values.yaml
Values File
replicaCount: 3
image:
repository: nginx
tag: "1.25"
service:
type: LoadBalancer
port: 80
resources:
limits:
cpu: 200m
memory: 256Mi
requests:
cpu: 100m
memory: 128Mi
ingress:
enabled: true
hostname: myapp.example.com
Managing Releases
helm list
helm list -n my-namespace
helm list --all-namespaces
helm status my-nginx
helm get values my-nginx
helm get values my-nginx --all
helm get manifest my-nginx
helm upgrade my-nginx bitnami/nginx --set replicaCount=5
helm upgrade my-nginx bitnami/nginx -f new-values.yaml
helm rollback my-nginx 1
helm history my-nginx
helm uninstall my-nginx
Creating Charts
Chart Structure
mychart/
βββ Chart.yaml # Chart metadata
βββ values.yaml # Default values
βββ charts/ # Dependencies
βββ templates/ # Kubernetes manifests
β βββ deployment.yaml
β βββ service.yaml
β βββ ingress.yaml
β βββ _helpers.tpl # Template helpers
β βββ NOTES.txt # Post-install notes
βββ .helmignore # Files to ignore
Chart.yaml
apiVersion: v2
name: myapp
description: A Helm chart for my application
type: application
version: 0.1.0
appVersion: "1.0.0"
dependencies:
- name: postgresql
version: "12.x.x"
repository: https://charts.bitnami.com/bitnami
condition: postgresql.enabled
values.yaml
replicaCount: 1
image:
repository: myapp
pullPolicy: IfNotPresent
tag: ""
nameOverride: ""
fullnameOverride: ""
service:
type: ClusterIP
port: 80
ingress:
enabled: false
className: ""
hosts:
- host: chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
resources: {}
postgresql:
enabled: true
auth:
database: myapp
Template Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "myapp.fullname" . }}
labels:
{{- include "myapp.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "myapp.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "myapp.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
{{- if .Values.resources }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- end }}
Helper Templates
{{/*
Create chart name and version
*/}}
{{- define "myapp.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "myapp.labels" -}}
helm.sh/chart: {{ include "myapp.chart" . }}
{{ include "myapp.selectorLabels" . }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "myapp.selectorLabels" -}}
app.kubernetes.io/name: {{ include "myapp.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
Template Functions
Common Functions
{{ .Values.name | upper }}
{{ .Values.name | lower }}
{{ .Values.name | title }}
{{ .Values.name | quote }}
{{ .Values.name | default "defaultValue" }}
{{ .Values.name | trim }}
{{- if .Values.ingress.enabled }}
{{- end }}
{{- range .Values.hosts }}
- host: {{ . }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
Indentation
resources:
{{- toYaml .Values.resources | nindent 2 }}
resources: {{ toYaml .Values.resources | indent 2 }}
Testing Charts
helm create myapp
helm lint ./myapp
helm template my-release ./myapp
helm template my-release ./myapp -f custom-values.yaml
helm install my-release ./myapp --dry-run --debug
helm package ./myapp
helm install my-release ./myapp
Chart Dependencies
helm dependency update ./myapp
helm dependency list ./myapp
helm dependency build ./myapp
Release Workflow
flowchart TB
A["helm install"] --> B["Render Templates"]
B --> C["Validate Resources"]
C --> D["Create Release"]
D --> E["Apply to Cluster"]
F["helm upgrade"] --> G["Render Templates"]
G --> H["Three-way Merge"]
H --> I["Update Release"]
I --> J["Apply Changes"]
K["helm rollback"] --> L["Get Previous State"]
L --> M["Apply Previous State"]
style A fill:#22c55e,color:#fff
style F fill:#3b82f6,color:#fff
style K fill:#f59e0b,color:#fff
Best Practices
| Practice |
Recommendation |
| Version charts |
Use semantic versioning |
| Use values files |
Separate configuration from templates |
| Document values |
Add comments explaining each value |
| Test before deploy |
Use --dry-run and helm lint |
| Pin chart versions |
Specify version in dependencies |
| Use namespaces |
Isolate releases by namespace |
Helm Commands Reference
helm repo add <name> <url>
helm repo update
helm repo list
helm repo remove <name>
helm search repo <keyword>
helm show values <chart>
helm show chart <chart>
helm pull <chart>
helm install <release> <chart>
helm upgrade <release> <chart>
helm rollback <release> <revision>
helm uninstall <release>
helm list
helm status <release>
helm history <release>
helm create <name>
helm lint <path>
helm template <release> <path>
helm package <path>
Key Takeaways
- Helm simplifies deployment - Package multiple manifests into one chart
- Values enable customization - Override defaults without changing templates
- Releases track state - Version and rollback deployments easily
- Templates use Go syntax - Learn sprig functions for complex logic
- Charts are reusable - Share and version your infrastructure
References