Kubernetes

Get Started with the Helm Kubernetes Package Manager

16 Apr 2022 3:00am, by

If you’re just starting your journey with Kubernetes, you’ve probably discovered just how challenging it can be to create full-stack manifests for applications. Once you’ve taken the time to get familiar with how applications and services are deployed, it does get much easier but even then writing out an entire manifest can be a slog.

That’s where Helm comes into play. Helm is a package manager and application management tool for Kubernetes that makes it considerably easier to deploy applications and services.

Think of Helm as the Kubernetes equivalent of apt or dnf. With this application, you can more easily deploy pre-built applications (and even customize them) to your Kubernetes cluster.

The magic behind Helm is Helm Charts, which is a packaged collection of pre-configured resources you use to deploy applications and services. By using Helm you dramatically increase your Kubernetes productivity while also making it easier to re-create successful deployments over and over.

Let’s walk through the process of installing Helm and then using it to find and download Helm charts that you can then use to deploy applications to your Kubernetes clusters.

The Helm Chart

Before we dive in, let’s talk about the structure of a Helm chart. A typical Helm chart will consist of the following files:

  • .helmignore – contains all the files that will be ignored when packaging the chart.
  • Chart.yaml – contains all the information about the chart being packaged (such as type, version, and appVersion).
  • Values.yaml – contains all definitions to be injected into templates.
  • charts – a directory that contains other charts your chart depends on.
  • templates – a directory that houses the manifest to be deployed.

After creating or downloading a chart, the directory structure might look like this:

├── charts
├── Chart.yaml
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── hpa.yaml
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── serviceaccount.yaml
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

Installing Helm

Before you install Helm, you must first make sure you have Kubernetes installed. To do that, read through my tutorial How to Deploy Kubernetes with Kubeadm and containerd. Once you have Kubernetes up and running, you can then install Helm.

Fortunately, the installation of Helm is quite simple. Log into your Kubernetes machine (one that you’ll be developing from) and issue the command:

curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 |bash

You should be prompted for your admin password. Once you successfully authenticate, the installation will start and complete. You can then verify the installation with the command:

helm version --short

You should see something like:

v3.8.1+g5cb9af4

Helm is now installed and ready to go.

Download the Stable Repository

The next task is to download the stable repository (which houses a large number of pre-configured Helm charts). To do this, issue the command:

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

Test to make sure the repository has successfully downloaded with the command:

helm repo list

You should see something like:

How to Search a Repository for a Chart

If you want to find out what charts are available from the stable repository, issue the command:

helm search repo stable

Here’s where the first issue raises its ugly head (and yet another reason why Kubernetes is so very complicated). When you run that search command, you’ll see the majority of those charts are deprecated (Figure 1).

 

Deprecated Helm charts found in the stable repo.

Figure 1: Deprecated Helm charts found in the stable repo.

The reason for this is the Cloud Native Computing Foundation no longer wanted to pay the rising cost of hosing a single, monolithic repository. Because of this, the charts are now hosted across various repositories via several different organizations.

Fortunately, there’s a solution for that in the ArtifactHub. From that site, you can search for just about any Helm chart your imagination can come up with.

For example, say I want to download the Helm chart for the Kubernetes Dashboard. I could go to the ArtifactHub, search for that application, and then see all of the necessary information for the chart. There’s even an INSTALL link that opens a popup giving you the necessary commands (Figure 2) for installing the repo and then the chart.

 

The installation instructions for the Kubernetes Dashboard.

Figure 2: The installation instructions for the Kubernetes Dashboard.

To install that Helm chart, you’d first add the repository with the command:

helm repo add k8s-dashboard https://kubernetes.github.io/dashboard

Immediately update the repository with:

helm repo update

Search the newly-added repository with:

helm search repo k8s-dashboard

You should see all of the applications included in the repository (in this case, it’s only one).

Once the repository has been added, install the chart with:

helm install my-kubernetes-dashboard k8s-dashboard/kubernetes-dashboard --version 5.3.1

The my-kubernetes-dashboard is a unique name you give the chart (which makes it possible to download the chart multiple times. The downloading of the chart can take some time (depending on the size and number of files).

In the  ~/.cache/helm/repository/ directory you should see the file kubernetes-dashboard-5.3.1.tgz. Unpack that file with the command:

tar xvzf ~/.cache/helm/repository/kubernetes-dashboard-5.3.1.tgz

You should now see a new directory, kubernetes-dashboard, in your current working directory. The structure of that directory looks like this:

├── Chart.lock
├── charts
│   └── metrics-server
│       ├── Chart.yaml
│       ├── ci
│       │   └── ci-values.yaml
│       ├── README.md
│       ├── templates
│       │   ├── apiservice.yaml
│       │   ├── clusterrole-aggregated-reader.yaml
│       │   ├── clusterrolebinding-auth-delegator.yaml
│       │   ├── clusterrolebinding.yaml
│       │   ├── clusterrole.yaml
│       │   ├── deployment.yaml
│       │   ├── _helpers.tpl
│       │   ├── NOTES.txt
│       │   ├── pdb.yaml
│       │   ├── psp.yaml
│       │   ├── rolebinding.yaml
│       │   ├── serviceaccount.yaml
│       │   └── service.yaml
│       └── values.yaml
├── Chart.yaml
├── README.md
├── templates
│   ├── clusterrolebinding-metrics.yaml
│   ├── clusterrolebinding-readonly.yaml
│   ├── clusterrole-metrics.yaml
│   ├── clusterrole-readonly.yaml
│   ├── configmap.yaml
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── ingress.yaml
│   ├── networkpolicy.yaml
│   ├── NOTES.txt
│   ├── pdb.yaml
│   ├── psp.yaml
│   ├── rolebinding.yaml
│   ├── role.yaml
│   ├── secret.yaml
│   ├── serviceaccount.yaml
│   ├── servicemonitor.yaml
│   ├── service.yaml
│   └── _tplvalues.tpl
└── values.yaml

You could comb through those files and make any necessary changes you need for the deployment.

After you’ve installed the chart you will see the instructions for deployment at the bottom. For example, the Kubernetes Dashboard deployment is handled with the following commands.

Get the Kubernetes Dashboard URL by running:

export POD_NAME=$(kubectl get pods -n default -l "app.kubernetes.io/name=kubernetes-dashboard,app.kubernetes.io/instance=my-kubernetes-dashboard" -o jsonpath="{.items[0].metadata.name}")

If the pod is successfully running, you should see output like this:

echo https://127.0.0.1:8443/

Finally, forward a local port to a port in the pod with:

kubectl -n default port-forward $POD_NAME 8443:8443

Once everything is up and running, you should be able to access the Kubernetes Dashboard (or whatever application/service you deployed with Helm).

And that, my friends, is how you get started with Helm. Kick the tires of this Kubernetes Package management system to become familiar so you can save time and effort with your Kubernetes deployments.

Even if you don’t actually deploy your applications with Helm charts, this is a great way to learn the ins and outs of creating a Kubernetes manifest. Download various charts and make sure to study the Chart.yaml file to learn more about how these manifests are created.