In plain and simple language, Helm is the package manager for Kubernetes. If we assume Kubernetes as an OS then Helm is Yum or apt. In Kubernetes, to install, uninstall, upgrade, update all tasks are performed using YAML manifests. Managing these YAMLs are a bit of pain. To manage these constant repeatable deployments, Helm creates a single package out of it. You can share this package, version it and manage it more easily compare to YAML. Helm has successfully simplified the process.
Helm was created to emphasize configuration re-usability. It can help to maintain a life-cycle for Kubernetes-based deployment. Helm is a CNCF project and developed in Go language.
In Kubernetes-based deployment, YAML manifests are everything. Kubernetes supports running many instances of multiple applications. Applications deployment needs complete lifecycle steps like deployment, upgrade, uninstall, rollback, etc. Maintaining these steps via YAML files is a tedious task. Helm sorted this via templates. You can create a template out of YAML and reuse it as per the requirement. The important feature is that you can pass values in this YAML file as variables. Let’s discuss Helm Components in detail
A command-line tool, which provides the user interface to work with Helm.
In Helm’s vocabulary, a package is called a chart. Every Chart consists few YAML configuration files and templates that are rendered into Kubernetes manifest files. Structure of Chart -
$ tree . ├── Chart.yaml ├── charts ├── templates │ ├── NOTES.txt │ ├── _helpers.tpl │ ├── deployment.yaml │ ├── hpa.yaml │ ├── ingress.yaml │ ├── service.yaml │ ├── serviceaccount.yaml │ └── tests │ └── test-connection.yaml └── values.yaml 3 directories, 10 files
Every directory and file has a specific function:-
- charts: For chart dependencies
- values.yaml: YAML file of default configuration values for the chart.
- templates: Contains template files with variables and variable default value comes from values.yaml and the command line. The templates use the Go programming language’s template format.
- Chart.yaml: File with metadata about the chart.
- LICENSE: plaintext license file
- README.md: Readme file
Chart repositories are web locations where packaged charts reside. You can use public repositories for Chart deployment or you can build your own private repository.
Each Helm chart comes with 2 separate versions:
- Chart version itself [version inChart.yaml]
- Application version in chart [appVersion in Chart.yaml]
Download binary release of the Helm on the client machine. Unpack the compressed file and move it to the desired destination (path variables)
$ curl -fsSL -o helm-v3.5.0-rc.2-linux-amd64.tar.gz https://get.helm.sh/helm-v3.5.0-rc.2-linux-amd64.tar.gz $ tar -xvzf helm-v3.5.0-rc.2-linux-amd64.tar.gz $ cd linux-amd64 $ sudo cp helm /usr/local/bin/
You can install Helm with a package manager as well as using Homebrew for macOS, Chocolatey for Windows, and Snap for Linux.
Helm Chart can be deployed using URL, directory, and file(compressed). I will install one chart using a public repository for demo purposes. This chart is Elasticsearch operator chart, available on Elasticsearch public repository.
To deploy the chart, you need to add a repository. Helm provides commands to add repositories. You can add multiple repositories as well.
$ helm repo add stable https://charts.helm.sh/stable $ helm repo add elastic https://helm.elastic.co
Once the repository is added, try to list it
$ helm repo list
We can list all charts available in the repository.
$ helm search repo elastic
If you want to search specific chart,
$ helm search repo eck
Search will not just look for package name, but it will look for string in other fields as well like description
Before using a repository for Chart deployment, make sure you update Chart Data
$ helm repo update
If you want to see values.yaml file. This command inspects a chart (directory, file, or URL) and displays the contents of the values.yaml file
$ helm show values elastic/eck-operator #You can list more details about Chart $ helm show chart elastic/eck-operator $ helm show all elastic/eck-operator
Installing a Chart
$ helm install elastic-operator elastic/eck-operator -n elastic-system --create-namespace # create-namespaces will help you to create namespace if not exist # helm install <chart-install-name> <chart-name>
In the above command, the installation will happen with default values available. Helm provides you the option of passing variable values at runtime as well.
Status of installation:
$ helm ls helm status <chart-install-name> # if the chart is deployed in another namespace $ helm ls --all-namespaces $ helm status elastic-operator -n elastic-system
History of Chart release
$ helm history elastic-operator -n elastic-system
Uninstalling a Chart
$ helm uninstall <chart-install-name>
Rollback! Helm keeps track of all the deployment and provides the feature of rolling back if required.
$ helm rollback elastic-operator 2 $ helm rollback <chart-release-name> <version>
Helm uses the default kubeconfig location to connect with the Kubernetes cluster. If you want to connect any other cluster for which kubeconfig is placed on another location then you need to update the following env variable
$KUBECONFIG (default "~/.kube/config")
apart from this variable, there are other variables as well. Please visit the documentation.
When you run commands like Helm Install or upgrade, the helm client connects to the Kubernetes cluster and store the record as Kubernetes secrets. You can see multiple rows, each belong to a specific revision and chart release. e.g.
use get secret to list all k8s secret
$ kubectl get secret
Helm uninstall will delete the chart deployed and the history attached to it. But if you want to keep the release information -
helm uninstall --keep-history
If you want to view helm client environment information.
$ helm env
It enables the verbose output when the helm command runs.
$ helm install elastic-operator elastic/eck-operator -n elastic-system --create-namespace --debug
Helm comes up with the dry run option for debugging. Use this option when you don’t want to install the chart but want to validate and debug only against the Kubernetes cluster. It is similar to kubectl dry-run option. It will validate the Chart deployment against the K8s cluster by loading the data into it.
$ helm install elastic-operator elastic/eck-operator -n elastic-system --create-namespace --values custom.yaml --dry-run
Helm templates get compiled against version of Kubernetes Cluster.
helm template helps you in template rendering. It will allow you to validate the templates which you created are generating the right YAMLs to be deployed.
Helm template does not do complete validation of the output. So make sure you use the template and dry-run together to get proper results.
You can use this to see which values were supplied during the release.
$ helm get values elastic-operator --revision 2 $ helm get values elastic-operator $ helm get manifest elastic-operator
Helm install creates a special type of Kubernetes secret that holds release information and deploys the chart if not present. If Chart is present on the cluster then it will fail. To upgrade any deployed chart release, you need to use an upgrade command. Helm provides another option for chart deployment which verifies the Chart is present or not, in case of yes then it will upgrade the chart or it will install the chart.
$ helm upgrade --install elastic-operator elastic/eck-operator
By default, Helm tracks up to ten revisions of each installation.
We have seen how to deploy or manage charts in the above examples. Now time is to understand how to create one. Helm comes up with the create command to create a sample chart.
$ helm create my-dummy-chart
It will generate the required files to start chart development. You can modify these files to chart for your application.
Helm stable and incubator chart repositories have been moved to GitHub and archived. The rest of the Charts have been moved to community-managed, repositories like Artifact Hub, Bitnami, etc
We can host our own repository using ChartMuseum, Harbor, a static web server (Apache), or another system.
That’s it for the post. I will cover more details on Helm in upcoming posts.
Thank you, Stay Safe and Keep learning.
Ref to Medium Post with images !