helm
Helm - the package manager for Kubernetes
- Helm is the Kubernetes package manager and is used to streamline installing and managing Kubernetes applications.
- Helm consists of the helm tool, which needs to be installed, and a chart.
- A chart is a Helm package, which contains the following:
- A description of the package
- One or more templates containing Kubernetes manifest files
Charts can be stored locally, or accessed from remote Helm repositories.
To use Helm, a few steps need to be performed:
- Optional: add repositories
- Find charts to install
- Install charts
- Manage the installed application
Helm doesn't come with a default repository.
The main site for finding Helm charts, is through https://artifacthub.io
Search for specific software here, and run the commands to install it; for instance, to run the Kubernetes Dashboard:
helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/helm install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard- The last command creates the local application name "kubernetes-dashboard" by installing the application "kubernetes-dashboard" from the repo "kubernetes-dashboard".
After adding repositories, use helm repo update to ensure access to the most up-to-date information.
Use helm install
to install the chart with default parameters.- Notice that a chart may be installed multiple times, which is why it's important to assign the right name.
After installation, use helm list to list currently installed charts.
Optionally, use helm delete to remove currently installed charts.
# you can install with snap
sudo snap install helm --classic
# Fetch the binary from https://github.com/helm/helm/releases; check for the latest release!
tar xvf helm-xxxx.tar.gz
sudo mv linux-amd64/helm /usr/local/bin
helm version
helm search <keyword>
# Add the Kubernetes Dashboard repo, then install it
helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
helm install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard
# Add the Bitnami repo and search its charts
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo list
helm search repo bitnami
helm search repo file
helm search repo nginx --versions
# Install a chart with a generated name, then inspect and manage it
helm install bitnami/mysql --generate-name
kubectl get all
helm show chart bitnami/mysql
helm show all bitnami/mysql
helm list [--all-namespaces]
helm status mysql-xxxx
Creating a template from a Helm Chart
- The helm template command can be used to write the configuration in a Helm chart to a YAML file without deploying the resources in the cluster.
- This allows you to generate a YAML file, allowing you to install the application using kubectl apply while still having the benefit of using the Helm chart parameters.
# Add the Argo repo, then render Argo CD to a YAML template without deploying
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
helm search repo argo/argo-cd
helm template my-argo-cd argo/argo-cd --version 7.7.14 > argo-cd-template.yaml
# Export default values, customize them, then render and apply
helm show values argo/argo-cd > values.yaml
# search for server.service.type: ClusterIP (line 2120) and change to NodePort
vim values.yaml
helm template my-argocd argo/argo-cd -f values.yaml > argo-cd-template.yaml
kubectl apply -f argo-cd-template.yaml
kubectl get all
kubectl delete -f argo-cd-template.yaml
Managing application with helm
Customizing Helm Applications
- A Helm chart consists of templates to which specific values are applied.
- The values are stored in the values.yaml file, within the Helm chart.
- Use helm show values to list current values (a lot!).
- Read documentation on artifacthub.io for a list of all values.
- Create a custom values.yaml which will be merged with the generic values.yaml file: helm install ... --values values.yaml
- When upgrading an application, you'll have to use --values values.yaml as well.
Overriding Values
- The default values.yaml file which is a part of the Helm chart contains default values which are defined as a key-value pair.
- To get information about useful values, check the documentation of the Helm chart: artifacthub.io is a good place to do so.
- While installing the chart, you can use a custom values.yaml file, provided with --values values.yaml as an argument to helm install to overwrite the default values.
- Alternatively, use helm install ... --set key=value to set individual values.
- Best practice: use a values.yaml file and only use --set when absolutely necessary.
# Add the repo, inspect specific values, customize them, then install and verify
helm repo add bitnami https://charts.bitnami.com/bitnami
helm show values bitnami/nginx
helm show values bitnami/nginx | grep commonLabels
helm show values bitnami/nginx | grep replicaCount
# Edit values.yaml and set:
# commonLabels: "type: helmapp"
# replicaCount: 3
vim values.yaml
helm install bitnami/nginx --generate-name --values values.yaml
helm list
helm get values nginx-xxxx
helm get values --all nginx-xxxx
Helm Upgrades
- A Helm chart is the package you install from the Helm repository.
- A Helm installation is an installed instance of that package.
- A Helm release is a combination between a chart and an installation.
- You can upgrade either of these.
- For instance, to first run a nginx installation without exposing it, use helm install bitginx bitnami/nginx --set ingress.enabled=false
- Next, to make the application accessible, use helm update bitginx bitnami/nginx --set ingress.enabled=true
- Use helm repo update to fetch the latest version of charts from the repository.
- Use helm upgrade bitginx bitnami/nginx to upgrade to the latest version of the application.
# Install nginx without ingress, then enable ingress to expose it
helm install bitginx bitnami/nginx --set ingress.enabled=false
helm update bitginx bitnami/nginx --set ingress.enabled=true
# Refresh repo metadata, then upgrade the release to the latest chart version
helm repo update
helm upgrade bitginx bitnami/nginx
Understanding Kustomize
- kustomize is a Kubernetes feature that uses a file with the name kustomization.yaml to apply changes to a set of resources.
- This is convenient for applying changes to input files that the user does not control himself, and which contents may change because of new versions appearing in Git.
- Use kubectl apply -k ./ in the directory with the kustomization.yaml and the files it refers to to apply changes.
- Use kubectl delete -k ./ in the same directory to delete all that was created by the Kustomization.
# sample kustomization.yaml
resources:
- deployment.yaml
- service.yaml
namePrefix: test-
namespace: testing
commonLabels:
environment: testing
Using Kustomization Overlays
- Kustomization can be used to define a base configuration, as well as multiple deployment scenarios (overlays) as in dev, staging, and prod, for instance.
- In such a configuration, the main kustomization.yaml defines the structure:
- base
- deployment.yaml
- service.yaml
- kustomization.yaml
- overlays
- dev
- kustomization.yaml
- staging
- kustomization.yaml
- prod
- kustomization.yaml
- In each of the overlays/{dev,staging,prod}/kustomization.yaml, users would reference the base configuration in the resources field, and specify changes for that specific environment:
# overlays/dev/kustomization.yaml
resources:
- ../../base
namePrefix: dev-
namespace: development
commonLabels:
environment: development
Page Source