Post

⎈ Getting Started with Helm: The Kubernetes Package Manager

A comprehensive guide to Helm, the package manager for Kubernetes. Learn about Helm charts, templates, values, and best practices for managing complex Kubernetes applications. Perfect for developers and DevOps engineers working with Kubernetes.

Introduction to Helm

Helm is the package manager for Kubernetes, helping you manage Kubernetes applications through Helm Charts. These charts provide templating, versioning, and dependency management for your Kubernetes manifests.

What We’ll Cover

  1. Understanding Helm concepts
  2. Installing and configuring Helm
  3. Working with existing charts
  4. Creating custom charts
  5. Advanced Helm features and best practices

Prerequisites

  • Kubernetes cluster (local or remote)
  • kubectl configured
  • Basic understanding of Kubernetes concepts

Installing Helm

# For macOS with Homebrew brew install helm # Verify installation helm version

Core Concepts

Charts

A Helm chart is a package of pre-configured Kubernetes resources:

  • Templates for K8s manifests
  • Values for customization
  • Chart metadata and dependencies
# Example chart.yaml apiVersion: v2 name: my-app description: A Helm chart for my application type: application version: 0.1.0 appVersion: "1.0.0"

Values

Values provide configuration that is injected into templates:

# values.yaml replicaCount: 3 image: repository: nginx tag: "1.21.1" service: type: ClusterIP port: 80

Templates

Templates are Kubernetes manifests with Go templating:

# templates/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 }}" ports: - containerPort: {{ .Values.service.port }}

Working with Helm Charts

Adding Repositories

# Add the official stable repository helm repo add stable https://charts.helm.sh/stable # Add Bitnami repository helm repo add bitnami https://charts.bitnami.com/bitnami # Update repositories helm repo update

Searching for Charts

# Search for available charts helm search repo wordpress # Get chart details helm show chart bitnami/wordpress # See all values helm show values bitnami/wordpress

Installing Charts

# Install with default values helm install my-release bitnami/wordpress # Install with custom values helm install my-release bitnami/wordpress \ --set wordpressUsername=admin \ --set wordpressPassword=password \ --set mariadb.auth.rootPassword=secretpassword # Install with values file helm install my-release bitnami/wordpress -f values.yaml

Creating Your Own Chart

Chart Structure

mychart/ Chart.yaml # Chart metadata values.yaml # Default values charts/ # Chart dependencies templates/ # Template files NOTES.txt # Usage notes deployment.yaml service.yaml _helpers.tpl # Template helpers

Create a New Chart

# Create a new chart helm create mychart # Lint the chart helm lint mychart # Package the chart helm package mychart

Template Functions and Pipelines

# Example of template functions metadata: name: {{ include "mychart.fullname" . }} labels: # Using conditionals apiVersion: networking.k8s.io/v1 kind: Ingress # Loops --- apiVersion: v1 kind: ConfigMap metadata: name: {{ .name }} data: :

Advanced Helm Features

Dependencies

Define dependencies in Chart.yaml:

dependencies: - name: mongodb version: 10.0.0 repository: https://charts.bitnami.com/bitnami condition: mongodb.enabled - name: redis version: 15.0.0 repository: https://charts.bitnami.com/bitnami condition: redis.enabled

Subcharts

Create reusable components:

# mychart/charts/mysubchart/values.yaml service: name: nginx type: ClusterIP

Hooks

Implement lifecycle hooks:

# templates/hooks/pre-install-hook.yaml apiVersion: batch/v1 kind: Job metadata: name: {{ .Release.Name }}-pre-install annotations: "helm.sh/hook": pre-install "helm.sh/hook-weight": "-5" "helm.sh/hook-delete-policy": hook-succeeded spec: template: spec: containers: - name: pre-install-job image: busybox command: ['sh', '-c', 'echo Pre-install job'] restartPolicy: Never

Best Practices

1. Chart Organization

  • Use consistent naming
  • Group related resources
  • Implement proper labels
# _helpers.tplapp.kubernetes.io/name: app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/version:

2. Values Management

  • Provide good defaults
  • Document all values
  • Use hierarchical structure
# values.yaml global: imageRegistry: "docker.io" imagePullSecrets: [] storageClass: "" application: replicaCount: 2 image: repository: nginx tag: latest pullPolicy: IfNotPresent

3. Security

  • Use RBAC
  • Implement network policies
  • Secure sensitive data
# templates/secret.yaml apiVersion: v1 kind: Secret metadata: name: {{ include "mychart.fullname" . }} type: Opaque data: :

Helm Commands Cheatsheet

# List releases helm list # Upgrade a release helm upgrade my-release bitnami/wordpress -f values.yaml # Rollback a release helm rollback my-release 1 # Uninstall a release helm uninstall my-release # Get release status helm status my-release # Get release history helm history my-release

Video Resources

Getting Started

Advanced Topics

Additional Resources

This post is licensed under CC BY 4.0 by the author.