Helm is a “package manager” for Kuberentes. It allows a simple, single command, to install and configure various software in a cluster. It also keeps track of ‘releases’ and allows you to roll back easily to any release. Helm exists in to parts, the helm
binary running from your workstation and the tiller
, running in the cluster and interacting with the Kubernetes api. This creates an interesting security challenge that we’ll discuss later. This curriculum will walk you through configuration and use of Helm in a Kubernetes cluster and touch on chart creation.
PreRequisites:
- General understanding of command line use including
kubectl
. - Specific understanding of Kubernetes primitives and yaml
- General understanding of templateing
- Specific knowledge of Golang Templating is helpful but not required
Definitions:
- Chart: A set of templates configured to deploy an application into Kubernetes.
- Release: The instance of the created application. Each
helm upgrade
orhelm install
command creates a new release - Values: The values used to configure the templated yaml. Most charts have sensible defaults and a few required values. Values can be passed in on the command line or through a yaml file(s)
- Helm: The local command
- Tiller: The in-cluster server component
Preparation:
- Setup Kubernetes using Kind, Minikube, k3s.io, or GKE:
- Install Helm on your workstation
- If RBAC is enabled in your cluster (which it should be), create a Role and RoleBinding for the Tiller.
- Create a Namespace for Tiller:
kubectl create namespace helm-system
- Create a ServiceAccount for Tiller:
kubectl -n helm-system create sa tiller
- Bind
cluster-admin
cluster role totiller
ServiceAccount:kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=tiller:tiller
- Create a Namespace for Tiller:
- Initialize Tiller
helm init --upgrade --tiller-namespace helm-system --service-account tiller
- Set Environment
export TILLER_NAMESPACE=helm-system
Working with Helm:
- Create a release:
helm install stable/redis
- This will install the basic Redis chart from the stable repository with a random name
- List releases:
helm list
- What name does your release have?
- What is the
STATUS
- Delete release:
helm delete <release-name>
- Create a new named release:
helm install stable/redis
--``name redis
- What namespace did it install into?
- How would you install it into a different namespace?
- List the pods
- Delete release
- Create the same release again
- Why did it fail?
- Do you see any releases?
- Helm stores a base64 encoded tar of each release in a ConfigMap in the namespace that Tiller is running in. Find it.
kubectl get -n tiller configmaps
- You will probably see two ConfigMaps, one that is from the randomly named release and one that is
redis.v1
- You could delete the individual ConfigMap manually but as the number of releases grows, that will become painful. Instead you can use the
--purge
flag helm delete redis
--``purge
will delete all ConfigMaps for the release.- FUN FACT: If your first release fails, you will always have to delete the release with purge. You can never ‘fix’ a release that is failed on its first install.
- What if you want to configure the chart outside other than the defaults?
- Use
helm inspect stable/redis
to see the templates and parameters and configuration information. Sometimes that is overwhelming so commonly, you can use the documentation. - Lets install the chart again, but with
rbac.create
turned on. This will configure the chart to create rbac roles and bindings for the redis pods.helm install stable/redis --name=redis
--``set rbac.create=true
- Lets also enable the metrics endpoint.
helm upgrade redis stable/redis
--``set rbac.create=true
--``set metrics.enabled=true
- Notice
upgrade
instead ofinstall
. Upgrade modifies an existing release, install creates a new one. You can do both in one command withhelm upgrade
--``install
- run
helm upgrade
--``help
to see more options. How could the above command be different if you used--reuse-values
. Do you think you’ll need to user--recreate-pods
for the Pods to get the new settings?
- Notice
- You can also use a yaml file to pass values into the
helm
command with the--values
flag.
- Use
helm init
stores the downloaded charts to~/.helm/
or to the value of$HELM_HOME
. You can see the charts you have downloaded locally by viewing that location- View the redis chart there or on github and open
/templates/redis-master-statefuleset.yml
. This is the Golang template language. The exact syntax is not important but you’ll notice that template blocks are wrapped in{{ }}
. Those that start withtemplate
are found in/templates/helpers.tpl
otherwise the are in they used directly as--set
or from the--values
file. You can see the default values file at/values.yml
. - Create your own chart:
helm create new-chart
- Open the chart and see what
templates
are created for you and what values are crated for you.- What app will this chart deploy by default?
- Will it deploy successfully as is? Try.
helm upgrade
--``install new-chart
Notice that because the chart is not coming from a repository likestable/redis
you just provide the path to the chart.
- Pick a simple app you’d like to install and convert this chart to deploy it.
- Make sure to use the
templates
innew-chart/templates/helpers.tpl
for consistency - What happens if you need to add a new file to
new-chart/templates
? Will helm automatically deploy it? Try. - How is
new-chart/templates/Notes.txt
used? Make sure to update it when you convert this chart to your chose app.
- Make sure to use the
- View
new-chart/Chart.yml
to view the metadata about yournew-chart
- Use a
--``values
file toupgrade
the release of this chart.
- Open the chart and see what