Helm is a package manager for Kubernetes. Helm uses a package format called 'Charts'. A Chart is a collection of files that describes a related set of Kubernetes resources. Just as apt is a package manager that makes software management easier in Ubuntu and Debian, Helm does the same for Kubernetes resources.
In this tutorial, we'll show you how to use the Helm package manager. Make sure you've followed our Helm package manager installation tutorial on the computer where you manage your Kubernetes cluster before using this guide.
- On Artifact Hub, you'll find available Helm Charts and a number of alternative repositories.
- For this tutorial, we assume that you're using the Bitnami Helm repository.
Using a Helm Chart
Step 1
Before using Helm, update the available repositories first (as in Linux):
helm repo update
Step 2
On the Artifact Hub website, you can search for available Helm Charts. An alternative is to do this directly from the command line with Helm:
helm search hub | grep softwarename
If you don't specify your search result with grep, you'll see all available charts in all available repositories.
Alternatively, you can also search directly through the repositories available on your computer:
helm search repo
You'll see a fairly large overview, but you can always specify your search query by specifying a repository and/or piping it to a grep command as follows:
helm search repo bitnami | grep mysql
Step 3
Before you install a Helm chart, you might want to see the contents of the chart. This can be done easily with the command:
helm show chart reponame/chartname
To continue with our previous example, you can view the Helm Chart for MySQL in the Bitnami repository as follows:
helm show chart bitnami/mysql
The contents of the Helm Chart may look like this:
annotations: category: Database apiVersion: v2 appVersion: 8.0.31 dependencies: - name: common repository: https://charts.bitnami.com/bitnami tags: - bitnami-common version: 2.x.x description: MySQL is a fast, reliable, scalable, and easy to use open source relational database system. Designed to handle mission-critical, heavy-load production applications. home: https://github.com/bitnami/charts/tree/main/bitnami/mysql icon: https://bitnami.com/assets/stacks/mysql/img/mysql-stack-220x234.png keywords: - mysql - database - sql - cluster - high availability maintainers: - name: Bitnami url: https://github.com/bitnami/charts name: mysql sources: - https://github.com/bitnami/containers/tree/main/bitnami/mysql - https://mysql.com version: 9.4.4
Step 4
As you would expect from a good package manager, you can easily install a Helm Chart. For this, use the 'helm install' command, for example:
helm install bitnami/mysql --generate-name
The output looks like this:
NAME: mysql-1670407849 LAST DEPLOYED: Wed Dec 7 11:10:51 2022 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: CHART NAME: mysql CHART VERSION: 9.4.4 APP VERSION: 8.0.31 ** Please be patient while the chart is being deployed ** Tip: Watch the deployment status using the command: kubectl get pods -w --namespace default Services: echo Primary: mysql-1670407849.default.svc.cluster.local:3306 Execute the following to get the administrator credentials: echo Username: root MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-1670407849 -o jsonpath="{.data.mysql-root-password}" | base64 -d) To connect to your database: 1. Run a pod that you can use as a client: kubectl run mysql-1670407849-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mysql:8.0.31-debian-11-r10 --namespace default --env MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD --command -- bash 2. To connect to primary service (read/write): mysql -h mysql-1670407849.default.svc.cluster.local -uroot -p"$MYSQL_ROOT_PASSWORD"
- In this example, we are assigned the name mysql-1670407849. When you install a chart in this way, you create a new 'release'. The number in the name is unique and is generated thanks to the --generate-name flag. This means that you can create multiple MySQL releases with the same chart within the same Kubernetes cluster. They are assigned a unique release name thanks to the --generate-name addition and can be managed independently of each other.
- Any additional steps, such as those needed to connect to your database, are usually displayed in the output of the installation command.
- More information about the helm install command can be found here.
Alternatively, you can also choose your own name. This is useful when you want to remember the names of your releases more easily and use the --keep-history flag, see the next paragraph.
helm install yourcustomname bitnami/mysql
The installation of your Helm Chart is complete.
Please note: At the time of writing, the Bitnami MySQL Helm Chart contains a bug that prevents the created Pod from starting. For some solutions, see this page.
Editing Helm Charts before installation
In certain cases, it is desirable to modify a Helm Chart, for example if you want to adjust the configuration or there is a bug in the Helm Chart. Fortunately, you can download and modify Helm Charts relatively easily in a few steps:
Step 1
Download the relevant Helm Chart with the command:
helm pull repo/chartname --untar
Replace repo with the name of the repository and chartname with the name of the Helm Chart, for example bitnami/mysql. The Chart is stored in a new directory within the directory you are currently working from, for example ~/
Step 2
In the folder that was just created (in our example ~/mysql), you will find all the files that are part of the Helm Chart. In practice, you usually only modify the values.yaml file located in the root directory. In our example, that's ~/mysql/values.yaml.
Step 3
After modifying the Helm Chart, package it with the command:
helm package chartname
Step 4
Install the Helm Chart with the command:
helm install chartname /directory/subdirectory/package-version.tgz
As before, replace chartname with the name of the chart and the directory and filename with those shown in Step 3.
Managing Helm Releases
When a Helm Chart is installed, it is called a 'release'. In this section, we will go through some useful management commands for managing Helm Charts on your Kubernetes cluster.
Checking Releases
You can easily see all the releases on your cluster with the command:
helm list
The output looks like this (note the scroll bar):
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-1670416172 default 1 2022-12-07 13:29:33.9111825 +0100 STD deployed mysql-9.4.4 8.0.31
You can get more specific information, similar to the output of the 'helm install' command, with:
helm status releasename
Deleting a Release
You can delete a release as easily as you installed it:
helm uninstall releasename
Replace 'releasename' with the name of the release as visible under 'NAME' in the output of the 'helm list' command.
Optionally, you can add the --keep-history flag. This is a handy option to retain information about the release:
helm uninstall releasename --keep-history
You can then later view the history of the 'releasename' release with the command:
helm history releasename
Helm goes even further: with this information, you can also roll back a release after uninstalling it with the command:
helm rollback releasename revision
You can find the revision number in the output of the 'helm history' command.
This concludes our tutorial on using Helm Charts for Kubernetes.