Helm is the package manager for Kubernetes, often called "apt/yum/homebrew for Kubernetes." It simplifies the deployment and management of Kubernetes applications by packaging them into reusable, versioned charts. This guide will teach you everything you need to know about Helm charts.
What is Helm?
Helm is a tool that streamlines installing and managing Kubernetes applications. Think of it as:
- Package Manager: Like npm for Node.js or pip for Python
- Template Engine: Uses Go templates to customize deployments
- Version Control: Manages different versions of your applications
- Release Manager: Tracks and manages application deployments
Why Use Helm?
Without Helm: You need to manually create and manage multiple YAML files:
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f configmap.yaml
kubectl apply -f secret.yaml
# ... and many more files
With Helm: One command installs everything:
helm install my-app ./my-chart
Key Benefits
- Simplified Deployment: Install complex applications with one command
- Reusability: Share and reuse chart templates
- Versioning: Manage different versions of your applications
- Configuration Management: Customize deployments using values
- Dependency Management: Handle application dependencies automatically
- Rollback Support: Easily revert to previous versions
Core Concepts
Helm Components
- Helm Client (
helm): Command-line tool for managing charts - Helm Charts: Packages of pre-configured Kubernetes resources
- Helm Releases: Installed instances of a chart
- Helm Repository: Collection of charts (like a package repository)
Chart Structure
A Helm chart has a specific directory structure:
my-chart/
├── Chart.yaml # Chart metadata
├── values.yaml # Default configuration values
├── templates/ # Kubernetes manifest templates
│ ├── deployment.yaml
│ ├── service.yaml
│ └── configmap.yaml
├── charts/ # Chart dependencies (subcharts)
└── README.md # Chart documentation
Installing Helm
Installation Methods
macOS:
brew install helm
Linux:
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
Windows:
choco install kubernetes-helm
Verify Installation:
helm version
Your First Helm Chart
Creating a Chart
# Create a new chart
helm create my-first-chart
# This creates a directory structure with example templates
Chart.yaml
The Chart.yaml file defines chart metadata:
apiVersion: v2
name: my-first-chart
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: "1.0.0"
values.yaml
Default configuration values:
replicaCount: 1
image:
repository: nginx
pullPolicy: IfNotPresent
tag: "1.21"
service:
type: ClusterIP
port: 80
ingress:
enabled: false
className: ""
annotations: {}
hosts:
- host: chart-example.local
paths:
- path: /
pathType: Prefix
tls: []
Template Example
Templates use Go template syntax to inject values:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "my-first-chart.fullname" . }}
labels:
{{- include "my-first-chart.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "my-first-chart.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "my-first-chart.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
ports:
- containerPort: 80
name: http
Installing and Managing Charts
Install a Chart
# Install from a local chart directory
helm install my-release ./my-chart
# Install with custom values
helm install my-release ./my-chart -f my-values.yaml
# Install with inline values
helm install my-release ./my-chart --set replicaCount=3
# Install from a repository
helm install my-release bitnami/nginx
List Releases
# List all releases
helm list
# List all releases in all namespaces
helm list --all-namespaces
Upgrade a Release
# Upgrade with new values
helm upgrade my-release ./my-chart --set replicaCount=5
# Upgrade from values file
helm upgrade my-release ./my-chart -f new-values.yaml
Rollback
# View release history
helm history my-release
# Rollback to previous version
helm rollback my-release
# Rollback to specific revision
helm rollback my-release 2
Uninstall
helm uninstall my-release
Working with Helm Repositories
Add Repositories
# Add official Bitnami repository
helm repo add bitnami https://charts.bitnami.com/bitnami
# Add custom repository
helm repo add my-repo https://my-repo.example.com/charts
Update Repositories
# Update all repositories
helm repo update
# Update specific repository
helm repo update bitnami
Search Charts
# Search in all repositories
helm search repo nginx
# Search with version filter
helm search repo nginx --versions
Install from Repository
helm install my-nginx bitnami/nginx
Advanced Helm Features
Chart Dependencies
Define dependencies in Chart.yaml:
dependencies:
- name: postgresql
version: "11.0.0"
repository: "https://charts.bitnami.com/bitnami"
- name: redis
version: "17.0.0"
repository: "https://charts.bitnami.com/bitnami"
Update dependencies:
helm dependency update
Template Functions
Helm provides many template functions:
# String functions
name: {{ .Values.name | upper }}
host: {{ .Values.host | default "localhost" }}
# Math functions
replicas: {{ mul .Values.replicaCount 2 }}
# Date functions
date: {{ now | date "2006-01-02" }}
# Include helper templates
{{- include "mychart.labels" . | nindent 4 }}
Conditional Logic
{{- if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "mychart.fullname" . }}
spec:
# ...
{{- end }}
Loops
env:
{{- range .Values.env }}
- name: {{ .name }}
value: {{ .value }}
{{- end }}
Real-World Examples
Example 1: Web Application Chart
# values.yaml
replicaCount: 3
image:
repository: myapp
tag: "v1.0.0"
service:
type: LoadBalancer
port: 80
ingress:
enabled: true
hosts:
- host: myapp.example.com
paths:
- path: /
pathType: Prefix
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
autoscaling:
enabled: true
minReplicas: 3
maxReplicas: 10
targetCPUUtilizationPercentage: 70
Example 2: Multi-Component Application
# Chart structure for microservices
my-app/
├── Chart.yaml
├── values.yaml
├── templates/
│ ├── frontend/
│ │ ├── deployment.yaml
│ │ └── service.yaml
│ ├── backend/
│ │ ├── deployment.yaml
│ │ └── service.yaml
│ └── database/
│ └── statefulset.yaml
Best Practices
1. Use Semantic Versioning
version: 1.2.3 # Major.Minor.Patch
2. Document Your Charts
Always include:
- README.md with usage instructions
- values.yaml with comments
- Chart.yaml with description
3. Validate Before Installing
# Dry run to see what would be installed
helm install my-release ./my-chart --dry-run --debug
# Validate chart syntax
helm lint ./my-chart
4. Use Values Files for Environments
# Development
helm install my-app ./my-chart -f values-dev.yaml
# Production
helm install my-app ./my-chart -f values-prod.yaml
5. Test Templates
# Render templates locally
helm template my-release ./my-chart
# Test with different values
helm template my-release ./my-chart --set replicaCount=5
6. Version Your Charts
Store charts in version control and tag releases:
git tag v1.0.0
git push origin v1.0.0
Troubleshooting
Chart Installation Fails
# Check chart syntax
helm lint ./my-chart
# Dry run to see errors
helm install my-release ./my-chart --dry-run --debug
# Check Kubernetes resources
kubectl get all
Values Not Applied
# Verify values are being read
helm get values my-release
# Check rendered templates
helm get manifest my-release
Dependency Issues
# Update dependencies
helm dependency update
# Check dependency status
helm dependency list
Release Not Found
# List all releases
helm list --all-namespaces
# Check release history
helm history my-release
Common Commands Reference
# Chart Management
helm create <chart-name> # Create new chart
helm lint <chart-path> # Validate chart
helm package <chart-path> # Package chart
helm template <release> <chart> # Render templates
# Release Management
helm install <release> <chart> # Install chart
helm upgrade <release> <chart> # Upgrade release
helm uninstall <release> # Remove release
helm list # List releases
helm status <release> # Show release status
helm rollback <release> [revision] # Rollback release
# Repository Management
helm repo add <name> <url> # Add repository
helm repo update # Update repositories
helm repo list # List repositories
helm search repo <keyword> # Search charts
Related Resources
Learning Path Navigation
📚 Learning Path: Kubernetes CI/CD and GitOps
Implement CI/CD pipelines and GitOps with Kubernetes
Navigate this path:
← Previous: Kubernetes Deployment Strategies | Next: Kubernetes Kustomize Best Practices →
Conclusion
Helm is an essential tool for managing Kubernetes applications. It simplifies deployment, enables reusability, and provides powerful templating capabilities. Start by creating simple charts, then gradually adopt more advanced features like dependencies and custom templates.
Key takeaways:
- Use Helm for all Kubernetes deployments
- Version your charts properly
- Test with dry-run before installing
- Use values files for different environments
- Document your charts thoroughly
With Helm, managing Kubernetes applications becomes much more manageable and scalable.