
Introduction to Helm and Creating your first Helm Chart
Helm is a package manager for Kubernetes. Similar to yum but for Kubernetes. It bundles all related manifests(such as deployment, service, etc.) into a chart. When installing chart, helm creates a release. The helm’s benefits it provide templating, repeatability, reliability, multiple environments, and ease of collaboration.
Installing Helm
$ curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 |bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 11213 100 11213 0 0 58630 0 --:--:-- --:--:-- --:--:-- 59015
Helm v3.4.1 is available. Changing from version v3.3.4.
Downloading https://get.helm.sh/helm-v3.4.1-linux-amd64.tar.gz
Verifying checksum... Done.
Preparing to install helm into /usr/local/bin
helm installed into /usr/local/bin/helm
- Verify helm version
$ helm version
version.BuildInfo{Version:"v3.4.1", GitCommit:"c4e74854886b2efe3321e185578e6db9be0a6e29", GitTreeState:"clean", GoVersion:"go1.14.11"}
- To check the current state of helm locally
$ helm env
HELM_BIN="helm"
HELM_CACHE_HOME="/home/cloud_user/.cache/helm"
HELM_CONFIG_HOME="/home/cloud_user/.config/helm"
HELM_DATA_HOME="/home/cloud_user/.local/share/helm"
HELM_DEBUG="false"
HELM_KUBEAPISERVER=""
HELM_KUBEASGROUPS=""
HELM_KUBEASUSER=""
HELM_KUBECONTEXT=""
HELM_KUBETOKEN=""
HELM_MAX_HISTORY="10"
HELM_NAMESPACE="default"
HELM_PLUGINS="/home/cloud_user/.local/share/helm/plugins"
HELM_REGISTRY_CONFIG="/home/cloud_user/.config/helm/registry.json"
HELM_REPOSITORY_CACHE="/home/cloud_user/.cache/helm/repository"
HELM_REPOSITORY_CONFIG="/home/cloud_user/.config/helm/repositories.yaml"
helm use the Kubernetes cluster/host via the config file
~/.kube/configHELM_DATA_HOME="/home/cloud_user/.local/share/helm"
HELM_DEBUG="false"
HELM_KUBEAPISERVER=""
HELM_KUBEASGROUPS=""
HELM_KUBEASUSER=""
HELM_KUBECONTEXT=""
HELM_KUBETOKEN=""
HELM_MAX_HISTORY="10"
HELM_NAMESPACE="default"
HELM_PLUGINS="/home/cloud_user/.local/share/helm/plugins"
HELM_REGISTRY_CONFIG="/home/cloud_user/.config/helm/registry.json"
HELM_REPOSITORY_CACHE="/home/cloud_user/.cache/helm/repository"
HELM_REPOSITORY_CONFIG="/home/cloud_user/.config/helm/repositories.yaml"
- helm use the Kubernetes cluster/host via the config file
~/.kube/config
Advantage of using helm
- Traditional deployments in Kubernetes is done with Kubectl across files into separately managed items. Helm deploys units called charts as managed releases.
- We can search for charts https://helm.sh/ . Charts can be pulled(downloaded) and optionally unpacked(untar).
Chart Repo
- The location where Helm charts can be stored and shared
- Respond to REST API GET requests to get packages
- Many storage options available — cloud buckets, local storage, GH Pages, etc. or we can use Chartmuseum(open-source helm chart repository).
- To show all the repos
$ helm repo list
NAME URL
istio.io https://storage.googleapis.com/istio-release/releases/1.4.2/charts/
- To add a repo
helm repo add <repo> url
helm repo add stable https://charts.helm.sh/stable
"stable" has been added to your repositories
- Search a repo
$ helm search repo mysql
NAME CHART VERSION APP VERSION DESCRIPTION
stable/mysql 1.6.7 5.7.30 Fast, reliable, scalable, and easy to use open-...
stable/mysqldump 2.6.2 2.4.1 DEPRECATED! - A Helm chart to help backup MySQL...
stable/prometheus-mysql-exporter 0.7.1 v0.11.0 DEPRECATED A Helm chart for prometheus mysql ex...
stable/percona 1.2.1 5.7.26 free, fully compatible, enhanced, open source d...
stable/percona-xtradb-cluster 1.0.6 5.7.19 free, fully compatible, enhanced, open source d...
stable/phpmyadmin 4.3.5 5.0.1 DEPRECATED phpMyAdmin is an mysql administratio...
stable/gcloud-sqlproxy 0.6.1 1.11 DEPRECATED Google Cloud SQL Proxy
stable/mariadb 7.3.14 10.3.22 DEPRECATED Fast, reliable, scalable, and easy t...
- Search in hub
$ helm search hub |head
URL CHART VERSION APP VERSION DESCRIPTION
https://hub.helm.sh/charts/gabibbo97/389ds 0.1.0 fedora-32 389 Directory Server
https://hub.helm.sh/charts/arhatdev/abbot 0.1.0 latest Network Manager Living at Edge
https://hub.helm.sh/charts/restorecommerce/acce... 0.1.2 0.1.6 A Helm chart for restorecommerce access-control...
https://hub.helm.sh/charts/ckotzbauer/access-ma... 0.4.1 0.4.1 Kubernetes-Operator to simplify RBAC configurat...
https://hub.helm.sh/charts/a10-prometheus-expor... 0.1.0 1.0 A Helm chart of A10 acos prometheus exporter fo...
https://hub.helm.sh/charts/k8s-at-home/adguard-... 2.2.0 v0.102.0 DNS proxy as ad-blocker for local network
https://hub.helm.sh/charts/mogaal/adminer 0.1.0 4.7.3 A Helm chart for Adminer
https://hub.helm.sh/charts/cetic/adminer 0.1.6 4.7.7 Adminer is a full-featured database management ...
https://hub.helm.sh/charts/graviteeio/ae 1.1.11 1.2.13 Official Gravitee.io Helm chart for Alert Engine
Creating your first chart
The easiest way to get started with chart is by using helm create command. The below command creates a new chart named myhelmchart.
helm create myhelmchart
Creating myhelmchart
- If you drill down inside the myhelmchart directory, you will see the structure like this. Let take a look at each of these files/directory one by one
myhelmchart
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml
templates
Templates are one of the most important directories, and this is where helm looks for your Kubernetes object yaml definitions(Deployment, Services,etc.).
values.yaml
If templates hold the resource definition, then values provide the way to parameterize it.
_helpers.tpl
Helm allows the use of Go templating in the resources files for Kubernetes. The _helpers.tpl is used to define Go template helpers.
NOTES.txt
This is the plain text file that gets printed out when the chart is successfully deployed. Usually, this contains the next step for using the chart.
Chart.yaml
This file contains the metadata such as chart version, application version, or constraints like a minimum version of Kubernetes/Helm, which is required to manage this chart. Some required fields in chart.yaml.

Now you understand all the chart structure and all the corresponding files, it’s time to create your first chart. I will start with a simple Nginx application, and later on, we will parameterize it using values.yaml.
Step1: Cleanup all the files inside the templates directory so that we will start from scratch.
rm -rf templates/*
Step2: Create deployment file
kubectl create deployment nginx --image=nginx --dry-run=client -o yaml >> templates/deployment.yaml
Step3: Expose your deployment
kubectl expose deploy nginx --port 80 --type NodePort --dry-run=client -o yaml > /tmp/service.yaml
Error from server (NotFound): deployments.apps "nginx" not found
Now the catch is that if you try to expose the deployment without creating it, you will encounter this error, fix it, and create deployment temporarily(as we want to deploy it using helm).
kubectl create deployment nginx --image=nginx
deployment.apps/nginx created
kubectl expose deploy nginx --port 80 --type NodePort --dry-run=client -o yaml > templates/service.yaml
As this my first chart, I want to keep it bare bone and define only the required values inside chart.yaml.
cat Chart.yaml
apiVersion: v2
name: myhelmchart
description: A Helm chart for Kubernetes
version: 0.1.0
- One more additional file I need to create is NOTES.txt inside the templates directory.
echo "This is first helm chart and it will deploy nginx application" >>templates/NOTES.txt
- I also cleanup rest of the files and directory to draw the clean slate
rm -rf values.yaml charts
Deploying your first chart
With all the config in place, it’s time to deploy the first helm chart. We can also set the release name so that we can refer it back at the later stages.
- It is always a good idea to run linter before deploying your chart to ensure there is no syntax error or follow all the best practices.
helm lint ./myhelmchart
==> Linting ./myhelmchart
[INFO] Chart.yaml: icon is recommended
[INFO] values.yaml: file does not exist
1 chart(s) linted, 0 chart(s) failed
- Let’s now start with a dry-run to make sure everything looks good
helm install demochart ./myhelmchart --dry-run
NAME: demochart
LAST DEPLOYED: Thu Feb 4 09:46:19 2021
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: myhelmchart/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: nginx
name: nginx
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: NodePort
status:
loadBalancer: {}
---
# Source: myhelmchart/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: nginx
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
NOTES:
This is first helm chart and it will deploy nginx application
- If things good deploy your helm chart without dry-run option
helm install demochart ./myhelmchart
NAME: demochart
LAST DEPLOYED: Thu Feb 4 09:47:56 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
This is first helm chart and it will deploy nginx application
- To verify it
helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
demochart default 1 2021-02-04 09:47:56.949383215 -0800 PST deployed myhelmchart-0.1.0
- Or you can access your application via hitting any of the Kubernetes nodes
curl http://172.19.0.2:32544/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
- We have created and deployed our first helm chart; it’s time to parameterize these values using values.yaml. Let target the deployment.yaml and parameterize the image
templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: nginx
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
- But before that how to uninstall your application using helm
helm uninstall demochart
release "demochart" uninstalled
helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
- Now go to values.yaml, and add key as imagename and its value as nginx
cat values.yaml
imagename: nginx
- Now to refer this value, you can specify it via Values and key so it should be like (.Values.imagename)
cat templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: nginx
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: {{ .Values.imagename }}
name: nginx
resources: {}
status: {}
- We can also bump up the version of helm chart
cat myhelmchart/Chart.yaml
apiVersion: v2
name: myhelmchart
description: A Helm chart for Kubernetes
version: 0.2.0
- Deploy it again
helm install demochart ./myhelmchart
NAME: demochart
LAST DEPLOYED: Thu Feb 4 10:38:25 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
This is first helm chart and it will deploy nginx application
Packaging Chart
You have your chart ready at this stage, but if you want to share these charts with your team or the rest of the community. To do that, use the helm package command.
helm package ./myhelmchart
Successfully packaged chart and saved it to: /home/prashant/Documents/helm/myhelmchart-0.2.0.tgz
- If your teammate need to install this chart, he can do it via helm install
helm install mychart myhelmchart-0.2.0.tgz
Wrapping Up
Helm is a powerful tool, and it greatly simplifies how you package your Kubernetes manifests. I barely scratched the surface in this blog, but if there is any helm feature you liked and want to share with the rest of the community, please mention that in the comment section.
Tag:automation, devops, docker, helm, kubernetes