DEV Community

loading...

Getting started with Helm v3

arunksingh16 profile image Arun Kumar Singh ・6 min read

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.

Introduction to Helm

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

Helm client

A command-line tool, which provides the user interface to work with Helm.

Chart

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
Enter fullscreen mode Exit fullscreen mode

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 Repository

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.

Version

Each Helm chart comes with 2 separate versions:

  1. Chart version itself [version inChart.yaml]
  2. Application version in chart [appVersion in Chart.yaml]

How to Install Helm?

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/
Enter fullscreen mode Exit fullscreen mode

You can install Helm with a package manager as well as using Homebrew for macOS, Chocolatey for Windows, and Snap for Linux.

How to Use Helm?

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
Enter fullscreen mode Exit fullscreen mode

Once the repository is added, try to list it

$ helm repo list
Enter fullscreen mode Exit fullscreen mode

We can list all charts available in the repository.

$ helm search repo elastic
Enter fullscreen mode Exit fullscreen mode

If you want to search specific chart,

$ helm search repo eck
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

History of Chart release

$ helm history elastic-operator -n elastic-system
Enter fullscreen mode Exit fullscreen mode

Uninstalling a Chart

$ helm uninstall <chart-install-name>
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

How Helm is connecting to Kubernetes Cluster?

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.

How Helm is keeping track of releases?

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. sh.helm.release.v1.elastic-operator.v1

use get secret to list all k8s secret

$ kubectl get secret
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Helm Configuration

If you want to view helm client environment information.

$ helm env
Enter fullscreen mode Exit fullscreen mode

Debug Helm Chart and Deployment

Use Debug flag

It enables the verbose output when the helm command runs.

$ helm install elastic-operator elastic/eck-operator -n elastic-system --create-namespace --debug
Enter fullscreen mode Exit fullscreen mode

Use Dry run

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
Enter fullscreen mode Exit fullscreen mode

Helm templates get compiled against version of Kubernetes Cluster.

Use Template

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.

Helm Get

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
Enter fullscreen mode Exit fullscreen mode

Helm Install or Helm Upgrade?

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
Enter fullscreen mode Exit fullscreen mode

By default, Helm tracks up to ten revisions of each installation.

How to create Helm Chart

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
Enter fullscreen mode Exit fullscreen mode

It will generate the required files to start chart development. You can modify these files to chart for your application.

Helm Official Chart Repository

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

Helm Self-host Chart Repository

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 !

Discussion (0)

pic
Editor guide