What is Helm and How to Use it?

Kubernetes Helm - Head Image

Helm is a powerful tool that simplifies the deployment and management of applications on Kubernetes. It acts as a package manager for Kubernetes, much like apt or yum for Linux, allowing users to define, install, and upgrade even the most complex Kubernetes applications. With Helm, system administrators and developers can streamline their workflows, reduce complexity, and ensure consistency across deployments. 

Managing applications at scale is a significant challenge. Kubernetes has become the de facto standard for container orchestration, but it comes with its own set of complexities. Helm addresses these by providing a way to bundle Kubernetes resources into a single package, making it easier to share and deploy applications. This guide aims to introduce you to Helm, covering its installation, key concepts, and practical usage, so you can start leveraging its capabilities in your Kubernetes environment. 

What is Helm?

Helm is an open-source tool designed to streamline the deployment and management of applications within a Kubernetes cluster. It functions as a package manager for Kubernetes, providing a standardized way to manage complex applications and services. 

Helm Definition and Purpose

Helm simplifies Kubernetes application deployment by using “charts,” which are pre-configured packages of Kubernetes resources. These charts enable users to deploy applications with a single command, ensuring consistency and reducing the risk of errors. 

Key Features of Helm

  • Package Management: Helm allows users to define, install, and upgrade Kubernetes applications using charts, which can be stored and shared via Helm repositories. 
  • Templating: Helm uses templates to define Kubernetes manifests, making it easy to customize deployments. 
  • Versioning: Helm charts support versioning, enabling users to track changes and roll back to previous versions if needed. 
  • Dependency Management: Charts can declare dependencies, ensuring that all required services are installed and configured correctly. 

Installing Helm

Installing Helm is a straightforward process, and it can be done on various platforms, including Linux, macOS, and Windows. Here is how you can get started with Helm on your system. 

System Requirements

Before you install Helm, ensure that you have the following prerequisites: 

– A Kubernetes cluster (version 1.16 or later recommended) 

– kubectl installed and configured to communicate with your Kubernetes cluster 

– curl or wget for downloading Helm 

Installation Steps for Different Platforms 

All the steps below, no matter for which operation, need to be executed in a terminal. 

For Linux and macOS it’s the terminal, for Windows it’s PowerShell. 

 Linux

  1. Download Helm: 

Run this command in your terminal to download the helm installation script from their official GitHub repository: 

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
  1. Run the installation script: 
chmod 700 get_helm.sh
./get_helm.sh

macOS

  1. Using Homebrew: 

Open the terminal and run this command to install helm using Homebrew: 

brew install helm
  1. Alternatively, download the binary: 
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 
chmod 700 get_helm.sh
./get_helm.sh

Windows

  1. Using Chocolatey: 
choco install kubernetes-helm
  1. Using Scoop: 
scoop install helm

Verifying the Installation

After installing Helm, verify the installation by checking the version using this command in a terminal: 

helm version

You should see output similar to: 

version.BuildInfo{Version:"v3.x.x", GitCommit:"xxxxx", GitTreeState:"clean", GoVersion:"go1.xx.x"} 

Understanding Helm Charts

Helm charts are perhaps the most important Helm functionality. The helm charts are collections of files that describe a related set of Kubernetes resources. Understanding the structure and key components of a Helm chart is important for effectively using Helm to manage your applications.

Structure of a Helm Chart

A Helm chart typically follows a standard directory structure, which includes several key files and directories:

mychart/
  Chart.yaml
  values.yaml
  charts/
  templates/

Key Components

  • Chart.yaml: This is the main file of a Helm chart. It contains metadata about the chart, such as its name, version, and description. 
apiVersion: v2
name: mychart
description: A Helm chart for Kubernetes
version: 0.1.0
  • values.yaml: This file contains the default configuration values for the chart. Users can override these values when deploying the chart. 
replicaCount: 1
image:
  repository: myimage
  tag: latest
  • charts/: This directory holds any dependencies for the chart. Dependencies are Helm charts themselves, which this chart relies on. 
  • templates/: This directory contains the Kubernetes manifest templates. These templates are rendered into Kubernetes manifests based on the values provided in values.yaml and any other user-specified values. 

  Example of a deployment template (`deployment.yaml`): 

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-myapp
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Release.Name }}-myapp
  template:
    metadata:
      labels:
        app: {{ .Release.Name }}-myapp
    spec:
      containers:
        - name: myapp
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"

Understanding these components allows you to create and customize Helm charts effectively. Charts provide a reusable, configurable, and shareable package format for deploying applications on Kubernetes. By using templates and values, Helm charts can be adapted to various environments and requirements, making them a powerful tool in your Kubernetes management toolkit. 

How to Create Your First Helm Chart

Creating your first Helm chart is an exciting step in learning to manage Kubernetes applications efficiently. This section will guide you through the process of creating a basic Helm chart and deploying a simple application. 

Step-by-Step Guide

  1. Create a New Helm Chart 

   Use the `helm create` command to scaffold a new chart: 

helm create mychart

   This command generates a directory structure with default files and directories, including `Chart.yaml`, `values.yaml`, and the `templates` directory. 

  1. Customize Chart.yaml 

   Open the `Chart.yaml` file and update it with appropriate metadata for your chart: 

apiVersion: v2
name: mychart
description: A Helm chart for a simple Kubernetes application
version: 0.1.0
  1. Edit values.yaml 

   Modify the `values.yaml` file to set default values for your chart. For example: 

replicaCount: 2
image:
  repository: nginx
  tag: stable
  1. Create Kubernetes Manifests in templates/ 

   In the `templates` directory, create a deployment template (`deployment.yaml`): 

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-nginx
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Release.Name }}-nginx
  template:
    metadata:
      labels:
        app: {{ .Release.Name }}-nginx
    spec:
      containers:
        - name: nginx
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
  1. Package the Chart 

   Once your chart is ready, package it using the `helm package` command: 

helm package mychart

   This command creates a `.tgz` file, which is the packaged version of your chart. 

Example Project

To illustrate, let us create a Helm chart for an Nginx web server: 

  1. Create the Chart: 
helm create nginx-chart
  1. Update Chart.yaml: 
apiVersion: v2
name: nginx-chart
description: A Helm chart for Nginx
version: 0.1.0
  1. Edit values.yaml: 
replicaCount: 2
image:
  repository: nginx
  tag: stable
  1. Create deployment.yaml in templates/: 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-nginx
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Release.Name }}-nginx
  template:
    metadata:
      labels:
        app: {{ .Release.Name }}-nginx
    spec:
      containers:
        - name: nginx
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
  1. Deploy the Chart: 
helm install my-nginx nginx-chart

Using Helm to Manage Applications

Helm not only simplifies the deployment of applications on Kubernetes but also makes managing those applications easier. This chapter covers how to install, upgrade, roll back, and manage application releases using Helm. 

Installing Applications Using Helm

To install an application using a Helm chart, use the `helm install` command followed by the release name and chart path or name: 

helm install my-release mychart/

– `my-release` is the name you give to this installation instance. 

– `mychart/` is the path to the chart you want to install. 

For example, to install the `nginx-chart` created in the previous chapter: 

helm install my-nginx nginx-chart/

Upgrading Applications with Helm

To upgrade an existing release to a new version of a chart or to update configuration values, use the `helm upgrade` command: 

helm upgrade my-release mychart/

You can also provide a new `values.yaml` file or specify new values directly in the command: 

helm upgrade my-release mychart/ --values new_values.yaml

or 

helm upgrade my-release mychart/ --set replicaCount=3

Rolling Back Applications

If an upgrade introduces issues, you can easily roll back to a previous release using the `helm rollback` command: 

helm rollback my-release 1

In this command, `1` refers to the revision number you want to roll back to. Helm keeps a history of releases, allowing you to revert to any previous state. 

Managing Application Releases with Helm

Helm provides several commands to help manage and view information about your releases: 

  • List all releases: 
  helm list
  • Get detailed information about a specific release: 
  helm status my-release
  • Uninstall a release: 
  helm uninstall my-release

Using these commands, you can maintain control over your application lifecycle, ensuring that deployments are smooth and manageable. Helm’s powerful features streamline the process of maintaining applications, making it easier to handle complex Kubernetes environments. 

Helm Repositories

Helm repositories are important for sharing and distributing Helm charts. A Helm repository is a simple HTTP server that houses packaged charts and an index file. Using Helm repositories, you can find and use charts created by others, and also share your own charts with the community. 

Adding and Using Helm Repositories

Helm comes with a default repository called Helm Hub, which aggregates charts from various sources. However, you can add other repositories to access a broader range of charts. 

  1. Add a Helm Repository: 

   Use the `helm repo add` command to add a new repository: 

helm repo add stable https://charts.helm.sh/stable

In this example, we add the stable repository which contains many popular charts. 

  1. Update Repositories: 

   After adding repositories, update them to get the latest list of charts: 

helm repo update
  1. Search for Charts: 

   Use the `helm search repo` command to find charts within the added repositories: 

helm search repo nginx

   This command searches for all charts related to Nginx in the added repositories. 

Using Charts from Repositories

Once you have added a repository and found a chart you want to use, installing it is straightforward. For example, to install the Nginx chart from the stable repository: 

helm install my-nginx stable/nginx

This command installs the Nginx chart, using default values. You can customize the installation by providing your own values file or using the `–set` flag to override specific values. 

Conclusion

Helm is a powerful tool that simplifies the management of Kubernetes applications by leveraging the concept of charts, which bundle multiple Kubernetes resources into a single package. By using Helm, developers and system administrators can deploy, upgrade, and manage applications more efficiently and consistently. 

Throughout this guide, we have covered the essential aspects of Helm, from understanding what it is and how to install it, to creating your own Helm charts and using them to manage applications. We also explored how to utilize Helm repositories to find and deploy a variety of pre-configured charts, further easing the management of Kubernetes environments. 

Recap of Key Points

  • Helm Overview: Helm is a package manager for Kubernetes, providing a standardized way to deploy and manage applications. 
  • Installation: Installing Helm is straightforward, with support for various operating systems. 
  • Helm Charts: Charts are the core units in Helm, containing all the necessary information to deploy applications. 
  • Creating Charts: You can create your own Helm charts to package your applications, making them reusable and shareable. 
  • Managing Applications: Helm simplifies application lifecycle management, including installation, upgrades, and rollbacks. 
  • Repositories: Helm repositories allow you to share and find charts, promoting community collaboration and reuse. 

Helm not only streamlines the deployment process but also enhances the scalability, reliability, and maintainability of your applications. By adopting Helm, you can focus more on developing and improving your applications rather than dealing with deployment complexities. 

Scroll to Top