Kubernetes Helm Charts: The Basics and a Quick Tutorial

What Are Kubernetes Helm Charts? 

Kubernetes Helm charts are the ‘packages’ of the Kubernetes world, similar to apt, yum, or homebrew for operating systems, or Maven, Gradle, and npm for programming languages. They are bundles of pre-configured Kubernetes resources.

Helm uses a packaging format called charts. A chart is a collection of files that describe a related set of Kubernetes resources. Charts are created as files laid out in a particular directory tree. They can be packaged into versioned archives to be deployed.

Helm charts allow for the simple creation, versioning, sharing, and publishing of applications that are designed to run on Kubernetes clusters. The use of Helm and Helm charts simplifies the process of defining, installing, and upgrading Kubernetes applications.

What Is a Helm Chart Repository? 

A Helm chart repository is a location where packaged charts can be stored and shared. Think of it as a library of applications ready to be deployed on Kubernetes. The repository indexes these packages so that they can be searched using Helm tooling. Technically, Helm repositories are HTTP servers that store packaged charts for distribution.

By default, Helm uses a public chart repository named stable, but you can configure it to use your own chart repository. This is especially useful for teams developing their own applications, as it allows them to store their charts in a central place and share them with others.

expert-icon-header

Tips from the expert

Itiel Shwartz

Co-Founder & CTO

Itiel is the CTO and co-founder of Komodor. He’s a big believer in dev empowerment and moving fast, has worked at eBay, Forter and Rookout (as the founding engineer). Itiel is a backend and infra developer turned “DevOps”, an avid public speaker that loves talking about things such as cloud infrastructure, Kubernetes, Python, observability, and R&D culture.

In my experience, here are tips that can help you better use Helm charts:

Use Helmfile for managing Helm charts

Helmfile simplifies managing multiple Helm charts by allowing you to define them declaratively.

Automate Helm chart testing

Use tools like Helm test or Chart Testing to automate the testing of your Helm charts before deploying them.

Utilize Helm secrets

Securely manage sensitive data in your Helm charts using Helm secrets for better security practices.

Create reusable templates

Design Helm templates to be reusable across multiple charts, reducing duplication and maintenance effort.

Use version constraints

Specify version constraints in your Chart.yaml to ensure compatibility with Kubernetes versions.

The Helm Deployment Process

Deploying applications using Helm involves pulling chart definitions from a repository, customizing them via configuration files, and then deploying the resulting application stack to a Kubernetes cluster: 

  1. Creating or selecting Helm chart: The chart includes all the necessary components like deployments, services, and ingress rules that describe how the application should be deployed and managed. 
  2. Defining a values.yaml file: You configure a YAML deployment using the values.yaml file. This file overrides default configuration values within the chart to tailor the application deployment to specific requirements, such as setting environment variables, configuring resource limits, or defining service ports.
  3. Installing the chart: After configuring the deployment, the helm install command is used to deploy the application to the Kubernetes cluster. This command takes the Helm chart, combines it with the configuration specified in the values.yaml file, and applies it to the cluster, resulting in the creation or update of Kubernetes resources. 
  4. Post-deployment: Helm provides commands like helm list to view active releases, helm upgrade to apply updates, and helm rollback to revert to a previous version of the deployment. 

Structure of a Helm Chart 

Chart Directory

The chart directory is the top-level directory, with the same name as the chart, which contains all the files and directories that make up the chart. This directory is the most important one as it’s where all the chart resources are stored.

Within this directory, you’ll find a collection of files and directories that define the chart. These include the Chart.yaml file, a templates directory, and a values.yaml file.

Templates Directory

The templates directory is where Kubernetes resources are defined as templates. These templates are standard Kubernetes manifest files, but with the addition of templating directives from the Go templating language.

This directory contains files that will be transformed into Kubernetes manifest files when the chart is deployed. The templates directory is flexible and can contain Kubernetes manifest files for any type of resource that is supported.

values.yaml

The values.yaml file is a simple, easy-to-read file that is used to customize the behavior of the chart. This file is written in YAML format and contains default configuration values for the chart.

These values can be overridden by the user during installation or upgrade, allowing for extensive customization of the chart’s behavior. In essence, the values.yaml file enables users to tailor deployments to their specific needs.

Here is an example of a values.yaml file:

# Default values for my-application.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
  repository: nginx
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: ""

service:
  type: ClusterIP
  port: 80

resources:
  limits:
    cpu: 100m
    memory: 128Mi
  requests:
    cpu: 100m
    memory: 128Mi

This file sets default values for a hypothetical application. It specifies the number of replicas (1), the image to be used (in this case, nginx), the service type and port, and resource limits and requests for the application to be deployed.

Chart.yaml

chart.yaml is a mandatory file that holds meta-information about the chart. It includes details like the chart’s name, its version and description. Here is an example of a chart.yaml file:

apiVersion: v2
name: my-application
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
type: application

# Chart version, should be incremented upon changes.
version: 0.1.0

# Application version this chart installs.
appVersion: "1.16.0"

This file defines the chart’s name (my-application), its description, the type of chart (application or library), the version of the chart, and the version of the application that the chart is installing.

How to Create and Use Helm Charts in Kubernetes  

Install Helm

Before we start with the installation process, it’s worth noting that Helm is compatible with macOS, Windows, and Linux. For the purpose of this tutorial, we’ll be using a Linux system. To install Helm, open your terminal and run the following commands:

curl https://baltocdn.com/helm/signing.asc | sudo apt-key add -

sudo apt-get install apt-transport-https --yes

echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list

sudo apt-get update

sudo apt-get install helm

Once you’ve run these commands, you can verify your Helm installation by running helm version. If Helm is successfully installed, you should see the version of your Helm client printed in the terminal.

Initialize a Helm Chart Repository

To initialize a Helm chart repository, we first need to add the official Helm charts repository, stable. We can do this by running the following command in our terminal:

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

Once we’ve added the stable repository, we can update our list of charts by running helm repo update. This command will fetch the latest versions of all the charts from the stable repository.

After we’ve updated our repository, we can search for charts using the helm search repo command. For instance, if we want to search for all charts related to MySQL, we can run helm search repo mysql.

Install an Example Chart

Now, let’s install an example chart to see Helm in action. For this tutorial, we’ll be using the WordPress chart from the Bitnami public repository. WordPress is a popular open-source content management system, and you can use Helm to automatically deploy it in your Kubernetes cluster.

To install the WordPress chart, run the following command in your terminal:

helm install my-wordpress 
oci://registry-1.docker.io/bitnamicharts/wordpress

This command will create a new deployment of WordPress in your Kubernetes cluster. Helm will download the WordPress chart from the repository, generate a set of Kubernetes resources based on the values defined in the chart, and apply these resources to your cluster.

Once the command has completed, you can check the status of your deployment by running helm status my-wordpress. This command will print detailed information about your deployment, including the status of each individual Kubernetes resource that was created by the chart.

Related content: Read our guide to Kubernetes helm tutorial (coming soon)

Visualizing and Managing Helm Charts With Komodor

Komodor’s platform streamlines the day-to-day operations and troubleshooting process of your Kubernetes apps. Specifically when it comes to Helm Charts, Komodor’s platform provides you with a visual dashboard to view the installed Helm charts, see their revision history and corresponding k8s resources. It also allows you to perform simple actions such as rolling back to a revision or upgrading to a newer version.

At its core, the platform gives you a real-time, high-level view of your cluster’s health, configurations, and resource utilization. This abstraction is particularly useful for routine tasks like rolling out updates, scaling applications, and managing resources. You can easily identify bottlenecks, underutilized nodes, or configuration drift, and then make informed decisions without needing to sift through YAML files or execute a dozen kubectl commands.

Beyond just observation, Komodor integrates with your existing CI/CD pipelines and configuration management tools to make routine tasks more seamless. The platform offers a streamlined way to enact changes, such as scaling deployments or updating configurations, directly through its interface. It can even auto-detect and integrate with CD tools like Argo or Flux to support a GitOps approach! Komodor’s “app-centric” approach to Kubernetes management is a game-changer for daily operational tasks, making it easier for both seasoned DevOps engineers and those new to Kubernetes to keep their clusters running smoothly, and their applications maintaining high-availability.

To learn more about how Komodor can make it easier to empower you and your teams to manage & troubleshoot K8s, sign up for our free trial.

Related content: Read our guide to helm dashboard