Understanding and Using Helm in Kubernetes

Introduction to Helm

Helm is a package manager for Kubernetes, enabling you to define, install, and manage Kubernetes applications. Think of it as the apt or yum for Kubernetes. Helm uses a packaging format called Charts.

Helm Architecture: Helm Client and Tiller

Helm 2

In Helm 2, the architecture was split between a client-side component called “Helm” and a server-side component called “Tiller.” Helm interacted with Tiller to deploy applications.

Helm 3

In Helm 3, the architecture has been simplified and Tiller has been removed. Everything is now client-side, which enhances security by removing the need for a server component that needs cluster-wide access.

Creating Helm Charts

A Helm Chart is a package that contains pre-configured Kubernetes resources. It has a specific directory structure:

  • Chart.yaml: Information about the chart
  • values.yaml: Default configuration file
  • templates/: Kubernetes YAML files with templating
  • charts/: Optional dependent charts

To create a new Chart:

helm create [CHART_NAME]

Installing and Managing Helm Releases

A Helm “release” is an instance of a chart running in a Kubernetes cluster.

  • Installing a Release:

    helm install [RELEASE_NAME] [CHART]
  • Upgrading a Release:

    helm upgrade [RELEASE_NAME] [NEW_CHART]
  • Rollback a Release:

    helm rollback [RELEASE_NAME] [REVISION]
  • Listing Releases:

    helm list
  • Uninstalling a Release:

    helm uninstall [RELEASE_NAME]

Helm Repositories and Best Practices


Helm Charts can be shared through Helm Repositories. Official charts are available in the default Helm repo, but you can also add your own:

  • Add Repo:

    helm repo add [REPO_NAME] [REPO_URL]
  • Update Repo:

    helm repo update
  • Search Repo:

    helm search repo [SEARCH_TERM]
Best Practices
  1. Version Control: Always keep your Helm charts in version control.
  2. Use Helm Hooks: For lifecycle management.
  3. Validate with Lint: Use helm lint to validate charts.
  4. Test Charts: Use helm test to test releases.
  5. Security: Be cautious when using third-party charts. Always review and understand what they do.

Example of Helm Chart with Template and Values

Directory Structure
|-- templates/
|   |-- deployment.yaml
|-- Chart.yaml
|-- values.yaml

This file describes the metadata about the Helm chart.

apiVersion: v2
name: my-nginx-chart
description: A Helm chart to deploy Nginx
version: 0.1.0

This file contains the default values for the chart.

replicaCount: 1
  repository: nginx
  tag: stable
  pullPolicy: IfNotPresent

This is a Kubernetes Deployment YAML file with Helm templating.

apiVersion: apps/v1
kind: Deployment
  name: my-nginx
  replicas: {{ .Values.replicaCount }}
      app: my-nginx
        app: my-nginx
      - name: my-nginx
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
Installing the Chart

To install this chart, you’ll first need to package it:

helm package my-nginx-chart

This will create a .tgz file that you can then install into your Kubernetes cluster:

helm install my-nginx-release my-nginx-chart-0.1.0.tgz
Overriding Values

You can override the default values.yaml settings during install or upgrade:

helm install my-nginx-release my-nginx-chart-0.1.0.tgz --set replicaCount=3

This command will deploy 3 replicas instead of the default 1.

And that’s a simple example of a Helm chart! This chart can be used to deploy an Nginx web server with configurable parameters like replicaCount and image.tag. It showcases how to use values.yaml for default values and templating in Kubernetes YAML manifests.