Overview
Helm is a cluster administration tool that manages charts on Kubernetes.
Helm relies on a packaging format called charts. Charts define a composition of related Kubernetes resources and values that make up a deployment solution. Charts are source code that can be packaged, versioned, and maintained in version control. Inside the chart are Kubernetes YAML files along with a templating language to allow contextual values to be injected into the YAMLs.
Helm also helps you manage the complexities of dependency management. Charts can include dependencies to other charts. Charts compliment your infrastructure as code processes. Use Helm effectively with a mature container versioning pipeline.
The Helm CLI tool deploys charts to Kubernetes. A server side component can accept the chart and submit the YAML declarations to Kubernetes. The chart is a deployable unit that can be inspected, listed, updated and removed.
This scenario covers version 3.x of Helm. If you are using version 2.x, it's highly advisable to move to the recent version.
Install Simple Redis Chart
Helm can be installed very easily as follows:
Install Helm
master $ 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 6827 100 6827 0 0 26231 0 --:--:-- --:--:-- --:--:-- 26157 Error: could not find tiller Helm v3.2.1 is available. Changing from version . Downloading https://get.helm.sh/helm-v3.2.1-linux-amd64.tar.gz Preparing to install helm into /usr/local/bin helm installed into /usr/local/bin/helm
After Helm is installed, we can check for its version:
Check version
master $ helm version --short v3.2.1+gfe51cd1 master $
Add Repo
Helm's default list of public repositories is initially empty. More on this later, but for now the Google chart repo can be added.
Add Repo
master $ helm repo add stable https://kubernetes-charts.storage.googleapis.com/ "stable" has been added to your repositories master $
In case that is little bit deprecated you can use:
Add Bitnami Repo
master $ helm repo add bitnami https://charts.bitnami.com/bitnami "bitnami" has been added to your repositories master $
The current local state of Helm is kept in your environment in the home location.
Check Variables
master $ helm env HELM_BIN="helm" HELM_DEBUG="false" HELM_KUBEAPISERVER="" HELM_KUBECONTEXT="" HELM_KUBETOKEN="" HELM_NAMESPACE="default" HELM_PLUGINS="/root/.local/share/helm/plugins" HELM_REGISTRY_CONFIG="/root/.config/helm/registry.json" HELM_REPOSITORY_CACHE="/root/.cache/helm/repository" HELM_REPOSITORY_CONFIG="/root/.config/helm/repositories.yaml"
The Helm command defaults to discovering the host already set in ~/.kube/config. There is a way to change or override the host.
Install Pre-Made Chart
Check a Hub
master $ helm search hub redis URL CHART VERSION APP VERSION DESCRIPTION https://hub.helm.sh/charts/choerodon/redis 0.2.5 0.2.5 redis for Choerodon https://hub.helm.sh/charts/inspur/redis-cluster 0.0.2 5.0.6 Highly available Kubernetes implementation of R... https://hub.helm.sh/charts/stable/prometheus-re... 3.4.0 1.3.4 Prometheus exporter for Redis metrics https://hub.helm.sh/charts/stable/redis-ha 4.4.4 5.0.6 Highly available Kubernetes implementation of R... https://hub.helm.sh/charts/bitnami/redis 10.6.13 6.0.1 Open source, advanced key-value store. It is of... https://hub.helm.sh/charts/hmdmph/redis-pod-lab... 1.0.1 1.0.2 Labelling redis pods as master/slave periodical... https://hub.helm.sh/charts/incubator/redis-cache 0.5.0 4.0.12-alpine A pure in-memory redis cache, using statefulset... https://hub.helm.sh/charts/enapter/keydb 0.8.0 5.3.3 A Helm chart for KeyDB multimaster setup https://hub.helm.sh/charts/hephy/redis v2.4.0 A Redis database for use inside a Kubernetes cl... https://hub.helm.sh/charts/dandydeveloper/redis-ha 4.5.6 5.0.6 Highly available Kubernetes implementation of R... https://hub.helm.sh/charts/bitnami/redis-cluster 2.1.0 6.0.1 Open source, advanced key-value store. It is of... https://hub.helm.sh/charts/softonic/redis-sharded 0.1.2 5.0.8 A Helm chart for sharded redis https://hub.helm.sh/charts/pozetron/keydb 0.5.1 v5.3.3 A Helm chart for multimaster KeyDB optionally w... master $
Don't foger that we added the public Repo:
List Repo
master $ helm repo list NAME URL stable https://kubernetes-charts.storage.googleapis.com/ master $
Let's exine further, which chart we can install:
Describe chart
master $ helm show chart stable/redis apiVersion: v1 appVersion: 5.0.7 deprecated: true description: DEPRECATED Open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. home: http://redis.io/ icon: https://bitnami.com/assets/stacks/redis/img/redis-stack-220x234.png keywords: - redis - keyvalue - database name: redis sources: - https://github.com/bitnami/bitnami-docker-redis version: 10.5.7 master $
Configure a namespace
Create a namespace for the installation target.
Create a namespace
master $ kubectl create namespace redis namespace/redis created master $
With a known chart name, use the install command to deploy the chart to your cluster.
Install Chart
master $ helm install my-redis stable/redis --namespace redis WARNING: This chart is deprecated NAME: my-redis LAST DEPLOYED: Sat May 16 19:29:23 2020 NAMESPACE: redis STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: This Helm chart is deprecated Given the `stable` deprecation timeline (https://github.com/helm/charts#deprecation-timeline), the Bitnami maintained Redis Helm chart is now located at bitnami/charts (https://github.com/bitnami/charts/). The Bitnami repository is already included in the Hubs and we will continue providing the same cadence of updates, support, etc that we've been keeping herethese years. Installation instructions are very similar, just adding the _bitnami_ repo and using it during the installation (`bitnami/<chart>` instead of `stable/<chart>`) ```bash $ helm repo add bitnami https://charts.bitnami.com/bitnami $ helm install my-release bitnami/<chart> # Helm 3 $ helm install --name my-release bitnami/<chart> # Helm 2 ``` To update an exisiting _stable_ deployment with a chart hosted in the bitnami repository you can execute ```bash $ helm repo add bitnami https://charts.bitnami.com/bitnami $ helm upgrade my-release bitnami/<chart> ``` Issues and PRs related to the chart itself will be redirected to `bitnami/charts` GitHub repository. In the same way, we'll be happy to answer questions related to this migration process in this issue (https://github.com/helm/charts/issues/20969) created as a common place for discussion. ** Please be patient while the chart is being deployed ** Redis can be accessed via port 6379 on the following DNS names from within your cluster: my-redis-master.redis.svc.cluster.local for read/write operations my-redis-slave.redis.svc.cluster.local for read-only operations To get your password run: export REDIS_PASSWORD=$(kubectl get secret --namespace redis my-redis -o jsonpath="{.data.redis-password}" | base64 --decode) To connect to your Redis server: 1. Run a Redis pod that you can use as a client: kubectl run --namespace redis my-redis-client --rm --tty -i --restart='Never' \ --env REDIS_PASSWORD=$REDIS_PASSWORD \ --image docker.io/bitnami/redis:5.0.7-debian-10-r32 -- bash 2. Connect using the Redis CLI: redis-cli -h my-redis-master -a $REDIS_PASSWORD redis-cli -h my-redis-slave -a $REDIS_PASSWORD To connect to your database from outside the cluster execute the following commands: kubectl port-forward --namespace redis svc/my-redis-master 6379:6379 & redis-cli -h 127.0.0.1 -p 6379 -a $REDIS_PASSWORD master $
It appears that is deprecated, be sure to use the Bitnami version, for which we have to add the repo first again and install it:
Install the Bitnami Regis
master $ helm repo add bitnami https://charts.bitnami.com/bitnami "bitnami" has been added to your repositories master $ helm install redis bitnami/redis NAME: redis LAST DEPLOYED: Fri May 22 13:23:40 2020 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: ** Please be patient while the chart is being deployed ** Redis can be accessed via port 6379 on the following DNS names from within your cluster: redis-master.default.svc.cluster.local for read/write operations redis-slave.default.svc.cluster.local for read-only operations To get your password run: export REDIS_PASSWORD=$(kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 --decode) To connect to your Redis server: 1. Run a Redis pod that you can use as a client: kubectl run --namespace default redis-client --rm --tty -i --restart='Never' \ --env REDIS_PASSWORD=$REDIS_PASSWORD \ --image docker.io/bitnami/redis:6.0.3-debian-10-r2 -- bash 2. Connect using the Redis CLI: redis-cli -h redis-master -a $REDIS_PASSWORD redis-cli -h redis-slave -a $REDIS_PASSWORD To connect to your database from outside the cluster execute the following commands: kubectl port-forward --namespace default svc/redis-master 6379:6379 & redis-cli -h 127.0.0.1 -p 6379 -a $REDIS_PASSWORD master $ helm ls NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION redis default 1 2020-05-22 13:23:40.824372834 +0000 UTC deployed redis-10.6.15 6.0.3 master $
Create Persistent Storage
Let's create couple persistant Volumes for storage:
Create Persistent Storage
master $ kubectl apply -f pv.yaml persistentvolume/pv-volume1 created persistentvolume/pv-volume2 created persistentvolume/pv-volume3 created master $ mkdir /mnt/data1 /mnt/data2 /mnt/data3 --mode=777 master $ cat pv.yaml kind: PersistentVolume apiVersion: v1 metadata: name: pv-volume1 labels: type: local spec: capacity: storage: 10Gi accessModes: - ReadWriteOnce hostPath: path: "/mnt/data1" --- kind: PersistentVolume apiVersion: v1 metadata: name: pv-volume2 labels: type: local spec: capacity: storage: 10Gi accessModes: - ReadWriteOnce hostPath: path: "/mnt/data2" --- kind: PersistentVolume apiVersion: v1 metadata: name: pv-volume3 labels: type: local spec: capacity: storage: 10Gi accessModes: - ReadWriteOnce hostPath: path: "/mnt/data3"