Deploying an application on K8s means writing 5–10 YAML files: Deployment, Service, Ingress, ConfigMap, Secret, HPA… and slightly different files for each environment (dev/staging/prod). Helm solves this problem.
What Is Helm and a Chart
Helm is a package manager for Kubernetes — like apt for Ubuntu or pip for Python.
Chart is a Helm package. It contains a set of YAML templates with variables and a values.yaml file with default values. A single helm install deploys the entire application.
Release is an installed instance of a Chart. You can install one Chart multiple times under different names and with different values.
Chart (template) → helm install → Release (running application)
Installing Helm
# macOS
brew install helm
# Verify
helm version
# version.BuildInfo{Version:"v3.14.0", ...}
helm install, upgrade, rollback, uninstall
Finding and Installing a Chart
# Add a repository
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
# Search for a chart
helm search repo postgresql
# NAME CHART VERSION APP VERSION DESCRIPTION
# bitnami/postgresql 13.2.0 16.1.0 PostgreSQL chart
# Inspect chart values
helm show values bitnami/postgresql | head -50
# Install
helm install my-postgres bitnami/postgresql \
--namespace database \
--create-namespace \
--set auth.postgresPassword=mysecretpassword \
--set primary.persistence.size=10Gi
# List installed releases
helm list -A
# NAME NAMESPACE REVISION STATUS CHART
# my-postgres database 1 deployed postgresql-13.2.0
Upgrading
# Update values without changing the chart version
helm upgrade my-postgres bitnami/postgresql \
--namespace database \
--set auth.postgresPassword=newsecretpassword
# Upgrade to a new chart version
helm upgrade my-postgres bitnami/postgresql \
--namespace database \
--version 13.3.0
# Upgrade with automatic rollback on failure
helm upgrade --install my-postgres bitnami/postgresql \
--atomic \
--timeout 5m
Rollback and Uninstall
# Release history
helm history my-postgres -n database
# REVISION STATUS CHART DESCRIPTION
# 1 superseded postgresql-13.2.0 Install complete
# 2 deployed postgresql-13.2.0 Upgrade complete
# Roll back to the previous revision
helm rollback my-postgres -n database
# Roll back to a specific revision
helm rollback my-postgres 1 -n database
# Uninstall (PVC data is preserved)
helm uninstall my-postgres -n database
values.yaml for Parameterisation
The main power of Helm is parameterisation via values.yaml. One Chart, different configs for different environments.
# values.yaml (default values)
replicaCount: 1
image:
repository: my-app
tag: "1.0.0"
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
ingress:
enabled: false
host: ""
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 256Mi
env:
LOG_LEVEL: info
DATABASE_HOST: postgres-service
# values-prod.yaml (overrides for production)
replicaCount: 3
image:
tag: "1.5.2"
ingress:
enabled: true
host: api.example.com
resources:
requests:
cpu: 500m
memory: 512Mi
limits:
cpu: 2000m
memory: 1Gi
env:
LOG_LEVEL: warning
# Install with a prod values file
helm install my-app ./my-chart \
-f values.yaml \
-f values-prod.yaml
# Or use --set for individual overrides
helm install my-app ./my-chart \
-f values.yaml \
--set image.tag=1.5.3
Popular Charts
# nginx Ingress Controller
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install ingress-nginx ingress-nginx/ingress-nginx \
--namespace ingress-nginx --create-namespace
# cert-manager (TLS certificates)
helm repo add jetstack https://charts.jetstack.io
helm install cert-manager jetstack/cert-manager \
--namespace cert-manager --create-namespace \
--set installCRDs=true
# Prometheus + Grafana (monitoring)
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install kube-prometheus prometheus-community/kube-prometheus-stack \
--namespace monitoring --create-namespace
Creating Your Own Chart
# Generate the chart skeleton
helm create my-app
my-app/
├── Chart.yaml # chart metadata
├── values.yaml # default values
├── charts/ # dependencies (sub-charts)
└── templates/ # YAML templates
├── deployment.yaml
├── service.yaml
├── ingress.yaml
├── _helpers.tpl # helper templates
└── NOTES.txt # message shown after install
# Chart.yaml
apiVersion: v2
name: my-app
description: A Helm chart for my application
type: application
version: 0.1.0 # chart version
appVersion: "1.0.0" # application version
# 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 }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.port }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
# Preview the rendered templates before installing
helm template my-app ./my-app -f values-prod.yaml
# Lint and dry-run
helm lint ./my-app
helm install my-app ./my-app --dry-run
# Real install
helm install my-app ./my-app -f values-prod.yaml
💬 Comments (0)
No comments yet
Be the first to share your opinion about this article!