Getting Started with Helm Kubernetes Package Manager – The New Stack

0

If you’re just starting your journey with Kubernetes, you’ve probably discovered how difficult it can be to create full-stack manifests for applications. Once you’ve taken the time to familiarize yourself with how apps and services are deployed, it becomes much easier, but even then, writing a full manifesto can be tedious.

This is where Helm comes in. Helm is a package manager and application management tool for Kubernetes that makes it much easier to deploy applications and services.

Think about Rod like the Kubernetes equivalent of apt or dnf. With this app, you can more easily deploy prebuilt apps (and even customize them) to your Kubernetes cluster.

The magic behind Helm is Helm Charts, which is a packaged collection of preconfigured resources that you use to deploy apps and services. By using Helm, you dramatically increase your Kubernetes productivity while making it easier to recreate successful deployments over and over again.

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

The bar table

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

  • .helmignore – contains all files that will be skipped when packaging the chart.
  • Chart.yaml – contains all information about the graph being packaged (such as type, version, and appVersion).
  • Values.yaml – contains all the definitions to inject into the models.
  • graphics – a directory that contains other charts that your chart depends on.
  • models – a directory that hosts the manifest to deploy.

After creating or uploading a chart, the directory structure may look like this:

├── graphics
├── Chart.yaml
├── models
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── entry.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── trials
│ └── test-connection.yaml
└── values.yaml

Installing Helms

Before installing Helm, you must first ensure that Kubernetes is installed. To do this, read my tutorial How to deploy Kubernetes with Kubeadm and containerd. Once Kubernetes is up and running, you can then install Helm.

Fortunately, installing Helm is fairly straightforward. Connect to your Kubernetes machine (the one you will be developing from) and run the command:

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

You should be prompted to enter your administrator password. After successful authentication, the installation starts and ends. 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 contains a large number of preconfigured Helm cards). To do this, run the command:

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

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

helm repo list

You should see something like:

How to find a repository for a chart

If you want to know what graphics are available in the stable repository, run the command:

helm search repo stable

This is where the first problem rears its head (and yet another reason why Kubernetes is so complicated). When you run this search command, you will see that the majority of these charts are outdated (Figure 1).

Figure 1: Outdated Helm charts found in the stable repository.

The reason is the Cloud Native Computing Foundation no longer wanted to pay the increasing cost of hosting a single monolithic repository. For this reason, graphics are now hosted in various repositories through several different organizations.

Fortunately, there is a solution to this in the ArtifactHub. From this site, you can search for just about any Helm chart your imagination can create.

For example, suppose I want to download the Helm chart for the Kubernetes dashboard. I could go to ArtifactHub, search for this app, and then see all the information needed for the graphic. There’s even an INSTALL link that opens a pop-up window giving you the necessary commands (Figure 2) to install the repository, then the graph.

Kubernetes dashboard installation instructions.

Figure 2: Kubernetes dashboard installation instructions.

To install this Helm chart, you must 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 the apps included in the repository (in this case there is only one).

Once the repository is 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 to the chart (which allows the chart to be downloaded multiple times. The chart may take some time to download (depending on the size and number of files).

In the ~/.cache/helm/repository/ you should see the kubernetes-dashboard-5.3.1.tgz file. Unzip this 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 this directory looks like this:

├── Chart.lock
├── graphics
│ └── metrics server
│ ├── Chart.yaml
│ ├── here
│ │ └── ci-values.yaml
│ ├── README.md
│ ├── models
│ │ ├── apiservice.yaml
│ │ ├── clusterrole-aggregated-reader.yaml
││├── clusterrolebinding-auth-delegator.yaml
│ │ ├── clusterrolebinding.yaml
│ │ ├── clusterrole.yaml
│ │ ├── deployment.yaml
│ │ ├── _helpers.tpl
│ │ ├── NOTES.txt
│ │ ├── pdb.yaml
│ │ ├── psp.yaml
│ │ ├── role binding.yaml
│ │ ├── serviceaccount.yaml
│ │ └── service.yaml
│ └── values.yaml
├── Chart.yaml
├── README.md
├── models
│ ├── clusterrolebinding-metrics.yaml
│ ├── clusterrolebinding-readonly.yaml
│ ├── clusterrole-metrics.yaml
│ ├── clusterrole-readonly.yaml
│ ├── configmap.yaml
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── entry.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 can browse these files and make the necessary changes you need for deployment.

After installing the board, you will see deployment instructions at the bottom. For example, the Kubernetes Dashboard deployment is managed 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 running successfully, you should see output like this:

echo https://127.0.0.1:8443/

Finally, redirect a local port to a pod port 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 any app/service you’ve deployed with Helm).

And that, my friends, is how you start with Helm. Start the tires of this Kubernetes package management system to get familiar with saving time and effort with your Kubernetes deployments.

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

Share.

Comments are closed.