Introduction

Managing multiple Kubernetes YAML files becomes complex quickly. Helm is the package manager for Kubernetes, simplifying deployment and management of applications through reusable templates called Charts.

What is Helm?

Helm packages Kubernetes resources into Charts - reusable, versioned, and shareable packages.

Key Concepts:

  • Chart: Package of Kubernetes resources
  • Release: Instance of a Chart running in cluster
  • Repository: Collection of Charts

Installing Helm

# macOS
brew install helm

# Linux
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

# Verify
helm version

Basic Commands

# Add repository
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update

# Search charts
helm search repo nginx
helm search hub wordpress

# Install chart
helm install my-release bitnami/nginx

# List releases
helm list

# Upgrade release
helm upgrade my-release bitnami/nginx

# Rollback
helm rollback my-release 1

# Uninstall
helm uninstall my-release

Installing Applications

Install WordPress:

helm repo add bitnami https://charts.bitnami.com/bitnami
helm install my-wordpress bitnami/wordpress \
  --set wordpressUsername=admin \
  --set wordpressPassword=password \
  --set mariadb.auth.rootPassword=secretpassword

Install with values file:

# values.yaml
wordpressUsername: admin
wordpressPassword: MySecurePassword
service:
  type: LoadBalancer
persistence:
  enabled: true
  size: 10Gi
helm install my-wordpress bitnami/wordpress -f values.yaml

Creating Custom Charts

Create chart:

helm create mychart

Chart structure:

mychart/
├── Chart.yaml          # Chart metadata
├── values.yaml         # Default values
├── charts/             # Dependencies
└── templates/          # Kubernetes manifests
    ├── deployment.yaml
    ├── service.yaml
    └── ingress.yaml

Chart.yaml:

apiVersion: v2
name: mychart
description: My Application
version: 1.0.0
appVersion: "1.0"

values.yaml:

replicaCount: 2
image:
  repository: nginx
  tag: "1.21"
  pullPolicy: IfNotPresent
service:
  type: ClusterIP
  port: 80

templates/deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}
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 }}"
        ports:
        - containerPort: 80

Install custom chart:

helm install myapp ./mychart
helm install myapp ./mychart --set replicaCount=3

Managing Releases

# Get release info
helm status my-release
helm get values my-release
helm get manifest my-release

# History
helm history my-release

# Upgrade
helm upgrade my-release bitnami/nginx --set replicaCount=3

# Rollback
helm rollback my-release 1

# Test
helm test my-release

Helm Repositories

# Add repos
helm repo add stable https://charts.helm.sh/stable
helm repo add bitnami https://charts.bitnami.com/bitnami

# List repos
helm repo list

# Update repos
helm repo update

# Remove repo
helm repo remove bitnami

Production Example

Deploy complete stack:

# Add repos
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

# Install NGINX Ingress
helm install nginx-ingress ingress-nginx/ingress-nginx \
  --namespace ingress-nginx \
  --create-namespace

# Install PostgreSQL
helm install postgres bitnami/postgresql \
  --set auth.postgresPassword=secretpassword \
  --set persistence.size=20Gi

# Install Redis
helm install redis bitnami/redis \
  --set auth.password=redispassword

# Install application
helm install myapp ./mychart \
  --set database.host=postgres-postgresql \
  --set redis.host=redis-master

Best Practices

  1. Use values files for configuration
  2. Version your charts
  3. Test before deploying
  4. Use namespaces
  5. Implement RBAC
  6. Document charts

Helm Commands Cheatsheet

# Repository
helm repo add <name> <url>
helm repo list
helm repo update
helm search repo <keyword>

# Install/Upgrade
helm install <release> <chart>
helm install <release> <chart> -f values.yaml
helm upgrade <release> <chart>
helm upgrade --install <release> <chart>

# Manage
helm list
helm status <release>
helm get values <release>
helm history <release>
helm rollback <release> <revision>
helm uninstall <release>

# Chart
helm create <chart>
helm package <chart>
helm lint <chart>
helm template <chart>

Conclusion

Helm simplifies Kubernetes application management through reusable, versioned packages.

Next: Monitoring with Prometheus & Grafana

Resources