Helm One Shot
Don’t think
helmis hard. It’s the same for K8s, what’saptfor Linux (Debian). That’s it!
Remember when you install something on Ubuntu, you just say apt install nginx and boom, done? Nobody sits and downloads ten different files and puts them one by one. Kubernetes people were doing exactly that, deployment.yaml first, then service.yaml, then this yaml, then that yaml. I got tired of it, then I found Helm. This is my little diary of how it went.
So What Is Helm?
Helm is the package manager for Kubernetes. Same idea as apt or dpkg on Linux, but for your cluster.
| Linux world | Helm world |
|---|---|
dpkg package | Chart |
apt repo | Helm repo |
apt install | helm install |
apt remove | helm uninstall |
| Installed package | Release |
A chart is just all your yaml manifests tied up in one bundle. A release is one installed copy of that chart in your cluster.
Note
Why “release” and not “deployment”? Because a chart does not always create a Deployment. Sometimes it is only a Pod, sometimes a whole bunch of things. So Helm uses one common word.
Where Do Charts Live?
Every popular app already has a chart, like Redis, nginx and so on. People put them in a repo and you just download from there.
| Repo | URL | What You Get |
|---|---|---|
| Bitnami | https://charts.bitnami.com/bitnami | Popular apps like nginx, redis, etc. |
| EKS Charts | https://aws.github.io/eks-charts | AWS made charts for EKS |
Bitnami is not the only one, it is just very common. And you can make your own repo for your company, or even for your customers.
Warning
Bitnami has changed how it publishes its images over the years. Before you use any chart in production, check which image it actually pulls and where from.
Start Here
Add a repo:
helm repo add bitnami https://charts.bitnami.com/bitnamiSee what repos you have:
helm repo listJust like apt update, refresh the repo once in a while:
helm repo update bitnamiSearch inside the repo:
helm search repo bitnamiOnly the one you want:
helm search repo bitnami | grep nginxInstall:
helm install my-nginx bitnami/nginxHere bitnami/nginx is the chart and my-nginx is the release name, your choice.
See it running:
helm list
kubectl get podsRemove it:
helm uninstall my-nginxThat is it. One shot install, one shot uninstall. No yaml chasing.
Make Your Own Chart
Create the template:
helm create login-app-busyboxYou get a folder like this:
Chart.yaml charts templates values.yaml| Thing | What It Is |
|---|---|
Chart.yaml | Metadata: chart version, app version, author, contact |
templates/ | Your k8s manifests (deploy.yaml, svc-acc.yaml, etc.) |
values.yaml | Your variables, change here and templates follow |
charts/ | Other charts this chart depends on |
Warning
helm create fills templates/ with a lot of sample files. Delete them all before adding yours, otherwise they will also get installed.
rm -rf login-app-busybox/templates/*Now put your own manifest inside. The {{ }} parts get filled from values.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-{{ .Chart.Name }}-{{ .Values.name }}-deployment
labels:
app: {{ .Values.name | quote }}
spec:
replicas: {{ .Values.spec.replicas }}
selector:
matchLabels:
app: {{ .Values.name | quote }}
template:
metadata:
labels:
app: {{ .Values.name | quote }}
spec:
containers:
- name: {{ .Values.name | quote }}
image: busybox
command:
- sh
- -c
- {{ printf "echo %s; sleep 3600" (.Values.message | quote) | quote }}Replace the whole values.yaml with this:
name: login-app
spec:
replicas: 2
message: Hello From Login App!Before packing, check it is not broken:
helm lint login-app-busybox/
helm template test login-app-busybox/helm template just prints the final yaml on your screen, nothing gets installed. Handy for seeing what your {{ }} turned into.
Want to try it right now, no repo needed?
helm install login-app ./login-app-busybox
kubectl get pods
helm uninstall login-appPack It And Make A Repo
Pack the chart:
helm package login-app-busybox/You get login-app-busybox-0.1.0.tgz. The version comes from Chart.yaml.
Create the index.yaml (this is the file that tells Helm what charts are in the repo):
helm repo index .Now your folder looks like this:
.
├── index.yaml
├── login-app-busybox
│ ├── Chart.yaml
│ ├── charts
│ ├── templates
│ │ └── deploy.yaml
│ └── values.yaml
└── login-app-busybox-0.1.0.tgzNote
You don’t need to host the login-app-busybox folder. Everything is already inside the .tgz. Only index.yaml and the .tgz are needed.
Tip
Made a change and want to release again? Bump version in Chart.yaml, run helm package again, then run helm repo index . again so index.yaml knows about the new one.
Host It On GitHub Pages
Push this to a GitHub repo and turn on GitHub Pages for it. Done, that same repo is now a Helm repo. No server, no money.
Now anyone can use it:
helm repo add my-helm-repo https://xyizlop.github.io/helm-repo-online/
helm search repo my-helm-repo
helm install login-app my-helm-repo/login-app-busyboxClean up when you are done playing:
helm uninstall login-app
helm repo remove my-helm-repoThat is how I went from chasing yaml files to typing one command. Pretty sweet deal.
