5.7 Helm

The previous sections showed the complexity of working with Kubernetes. As in other programming languages, there are easier ways to manage an application rather than writing all of the deployments and services of an application by hand. Among others, Helm is a package manager for Kubernetes that enables to template and group Kubernetes manifests as versioned packages.

Helm applications are a collection of yaml and helper templates. Once an application is packaged, it can be installed onto a Kubernetes cluster using a single command. Helm applications are packaged as tar files and stored in repositories similar to registries like Docker or PyPi, and some repository registries like Artifactory automatically index Helm Charts. This ease of working allows Helm to provide a large collection of open-source charts to easily deploy applications such as PostgreSQL, Redis, Nginx, and Prometheus.

5.7.1 Helm Chart Structure

As previously mentioned, a Helm package consists of a Helm Chart that includes a collection of yaml and helper templates. This chart is finally packaged as a .tar file. The following structure shows how the chart my-custom-chart is organized in the directory custom_chart. The Chart.yaml file consists of the major metadata about the chart, such as name, version, and description, as well as dependencies if multiple charts are packaged. The /templates directory contains all the Kubernetes manifests that define the behavior of the application and are deployed automatically by installing the chart. Exemplary variables able to be specified are denoted in the values.yaml file, which also incorporates default values. Just like a .gitignore file it is also possible to add a .helmignore.

custom_chart/
├── .helmignore         # Contains patterns to ignore 
├── Chart.yaml          # Information about your chart
├── values.yaml         # The default values for your templates
└── templates/          # The template files
    └── ingress.yaml    # ingress.yaml manifest, 
    └── ...             # and others...

When wanting to create a own Helm Chart, there is no need to create all the files on your own. To bootstrap a Helm Chart there is the in-built command:

helm create <my-chart>

that provide all the common Kubernetes manifests (deployment.yaml, hpa.yaml , ingress.yaml , service.yaml , and serviceaccount.yaml) as well as helper templates to circumvent resource naming constraints and labels/annotations. The command will provide a scalable deployment for nginx on default, which can be simply modified to deploy a custom docker image by editing the values.yaml file.

5.7.2 Working with Helm

As there is large collection of open-source and public charts already available, there is no need to create your own Helm Chart. One simply can use helms build in command to search for a specific Helm Chart, such as shown below by searching for a redis deployment, or have a look oneselves by scrolling through for example artifactory or bitnami, which provide a large collection of public charts.

helm search hub redis

5.7.2.1 Adding a Helm Chart to the local setup.

After finding the correct Helm Chart, it can simply be added to the local setup. Once added to the local setup, the chart is listed in the local repository and is ready to be installed.

# Add a helm chart to the local setup under the name "bitnami"
helm repo add bitnami https://charts.bitnami.com/bitnami

# Search and show the local repository for all charts with the name bitnami
# Once it a helm chart is listed here it can be installed
helm search repo bitnami

Since Helm harts are packaged as a .tarfile, they can also be downloaded locally and modified as needed.

# Download the nginx-ingress-controller helm chart to local
helm pull bitnami/nginx-ingress-controller --version 5.3.19

5.7.2.2 Installing a Helm Chart

Once a Helm Chart is downloaded or added to the local setup, it can be installed using the helm install command followed by a custom release name, and the name of the chart to be installed. It is a best practice to update the list of charts before installing, just like when installing packages in other programming languages such as Pip and Python.

# Make sure we get the latest list of charts
helm repo update

# Installing a Helm Chart from the local repository
# helm install <CUSTOM-RELEASE-NAME> <CHART-NAME>
helm install custom-bitnami bitnami/wordpress

# Installing a downloaded Helm Chart from a directory
helm install -f values.yaml my-custom-chart ./custom_chart

Similar to installing a Helm Chart, it can also be uninstalled.

# helm uninstall <CUSTOM-RELEASE-NAME>
helm uninstall custom-bitnami
helm uninstall my-custom-chart

All installed and released charts can be listed using the following command.

helm list