Managing Kubernetes deployments efficiently can be challenging, especially as environments grow larger and more complex. Helm, Kubernetes’ package manager, simplifies lifecycle management by representing configurations as reusable templates called charts. Helm makes it easy to deploy, upgrade, and manage applications in Kubernetes clusters.
This complete tutorial covers foundational Helm concepts, steps to install and upgrade charts, how to create custom Helm charts, and managing chart dependencies.
Table of Contents
- What is Helm? Concepts and Basics
- Installing and Upgrading Helm Charts
- Creating a Custom Helm Chart
- Using Dependencies in Helm
- Final Thoughts
What is Helm? Concepts and Basics
Helm is a tool that streamlines Kubernetes deployment configurations into reusable packages called charts. Charts are collections of YAML files and templates that define Kubernetes resources.
Charts
A Helm chart is a package containing Kubernetes resource configurations. It consists of these components:
- Charts: Templates for Kubernetes objects like Deployments, Services, and ConfigMaps.
- Values: Override default configurations with custom inputs.
- Dependencies: Reusable charts nested as subcharts.
Directory Structure of a Helm Chart:
my-chart/
Chart.yaml # Metadata about the chart
values.yaml # Default configuration values
templates/ # Kubernetes manifests in template format
deployment.yaml # Sample Deployment resource
service.yaml # Sample Service resource
Values
Values are dynamic inputs to Helm templates. They allow users to customize a chart. For example:
- A chart might define
replicas
in thevalues.yaml
file:replicas: 3
Users can override this with a custom values.yaml
during Helm installation:
helm install my-app ./my-chart -f custom-values.yaml
Templates
Templates use Go templating to dynamically render Kubernetes manifests. For example:
spec:
replicas: {{ .Values.replicas }}
When a user provides replicas = 3
in the values.yaml
, Helm renders:
spec:
replicas: 3
Key Takeaways:
- Chart = Static package.
- Values.yaml = Dynamic inputs.
- Template = Customizable resource file generated at runtime.
Installing and Upgrading Helm Charts
Helm simplifies the process of deploying charts by using the helm install
and helm upgrade
commands.
Installing a Helm Chart
Step 1: Add a Helm Repository
Helm repos host charts for deployment. For example, add the official Bitnami repo:
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
Step 2: Install a Chart
Use helm install
to deploy a chart in a Kubernetes cluster:
helm install my-mysql bitnami/mysql
Command Breakdown:
my-mysql
is the release name.bitnami/mysql
points to the MySQL chart in the Bitnami repo.
Check running resources:
kubectl get all
Upgrading a Helm Chart
Helm uses helm upgrade
to modify or redeploy an existing release.
Update with an override:
helm upgrade my-mysql bitnami/mysql --set auth.rootPassword=MySecurePass
View the status of the deployed release:
helm status my-mysql
Diagram of Installation and Upgrade:
The chart templates are rendered dynamically and sent to the Kubernetes API server for deployment.
Creating a Custom Helm Chart
Creating custom Helm charts allows you to package your application’s resources for easy deployment.
Step 1 – Create a Chart Skeleton
Use helm create
to scaffold a new chart:
helm create my-app
Generated Directory Structure:
my-app/
Chart.yaml # Metadata (name, version, description)
values.yaml # Configurable parameters
templates/ # Kubernetes templates
deployment.yaml # Default Deployment manifest
service.yaml # Default Service manifest
Step 2 – Edit Templates
Customize Kubernetes templates, for example, deployment.yaml
in templates/
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-app
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ .Release.Name }}
spec:
containers:
- name: app
image: nginx
ports:
- containerPort: 80
Step 3 – Define Default Values
Update values.yaml
to specify default settings:
replicas: 2
Step 4 – Install and Test
Deploy the chart:
helm install my-app ./my-app
Test the deployment:
kubectl get pods
Optional – Packaging and Sharing the Chart
Helm can package a chart into a .tgz
file:
helm package my-app
The packaged chart can be distributed or uploaded to a Helm repository.
Using Dependencies in Helm
Helm supports dependencies between charts, allowing one chart to include reusable subcharts.
Step 1 – Add a Dependency
Edit the main chart’s Chart.yaml
to reference dependent charts:
dependencies:
- name: redis
version: 16.0.0
repository: https://charts.bitnami.com/bitnami
Step 2 – Update Dependencies
Download the listed dependencies with:
helm dependency update ./my-app
Helm downloads the Redis chart and places it in the charts/
directory.
Step 3 – Use Dependency Values
Override dependencies in values.yaml
:
redis:
auth:
password: myredissecret
Deploy with dependencies:
helm install my-app ./my-app
Visual Reference of Dependence Flow:
The parent chart (my-app
) uses the Redis subchart to deploy both resources seamlessly.
Final Thoughts
Helm charts simplify Kubernetes deployments by transforming configurations into reusable packages. With the ability to customize templates, manage dependencies, and handle upgrades effortlessly, Helm is essential for any Kubernetes developer or operator.
Use this guide as your go-to resource for getting started with Helm, mastering advanced concepts, and navigating real-world deployments. Start managing Kubernetes workloads with confidence today!