Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Latest commit

Β 

History

History

3-helm

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 

Helm

Prerequisites

Summary

In this module you will learn :

  • What is Helm and how to use it
  • What is a Chart and how to create one

Context

As you saw in the second module Kubernetes Basics and cluster created, the default way to deploy objects in Kubernetes is by using kubectl with yaml files.

For example, if we want to deploy a pod running nginx and then make it available from an external IP using a service you will need to describe at least these two objects such as :

Deployment :

apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template: # create pods using pod definition in this template
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

Service :

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  ports:
  - port: 8000 
    targetPort: 80
    protocol: TCP
  type: LoadBalancer
  selector:
    app: nginx

The problem with this approach is that when you need to make an update to your solution, you will need to update it across different yaml files.

Let's say you want to change the name of the app from nginx to nginx-production. You have to change it in a few places in the deployment and not forget to change the selector setting in the service as well.

This is one example among others where Helm is fixing the issue by being able to create and use templates.

Helm and Chart

Helm is the package manager for Kubernetes.

A package is named a Chart.

You can either create you own, or pull and install an official one such as Wordpress, GitLab, Apache Spark, etc...

You can find a list of the official ones here : https://github.com/kubernetes/charts/tree/master/stable

To use Helm, you need to have the CLI installed on your machine

Before using Helm with your cluster, make sure you have the Tiller component running in your cluster.

kubectl get pod --all-namespaces | grep tiller

If you do not see Tiller running and if you have an RBAC-enabled cluster, you need a service account and role binding for the Tiller service in your cluster. To install these components, refer to these guides to create a service account and configure helm to initialize Tiller in the cluster.

Once Tiller service is up and running in the cluster and you have initialized helm, let's try to deploy an official Chart such as the popular Wordpress

helm install stable/wordpress

Note: If you have an error such has Error: incompatible versions client[v2.7.0] server[v2.6.2], please run helm init --upgrade

After a few seconds you should see the following output in your terminal :

...
NAME:   cloying-crocodile
LAST DEPLOYED: Wed Nov 22 11:29:55 2017
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1beta1/Deployment
NAME                         DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE
cloying-crocodile-mariadb    1        1        1           0          10s
cloying-crocodile-wordpress  1        1        1           0          10s

==> v1/Pod(related)
NAME                                          READY  STATUS   RESTARTS  AGE
cloying-crocodile-mariadb-1648957417-0prvc    0/1    Pending  0         10s
cloying-crocodile-wordpress-3958361718-z9qr3  0/1    Pending  0         10s

==> v1/Secret
NAME                         TYPE    DATA  AGE
cloying-crocodile-mariadb    Opaque  2     10s
cloying-crocodile-wordpress  Opaque  2     10s

==> v1/ConfigMap
NAME                       DATA  AGE
cloying-crocodile-mariadb  1     10s

==> v1/PersistentVolumeClaim
NAME                         STATUS   VOLUME   CAPACITY  ACCESS MODES  STORAGECLASS  AGE
cloying-crocodile-mariadb    Pending  default  10s
cloying-crocodile-wordpress  Pending  default  10s

==> v1/Service
NAME                         TYPE          CLUSTER-IP    EXTERNAL-IP  PORT(S)                     AGE
cloying-crocodile-mariadb    ClusterIP     10.0.163.26   <none>       3306/TCP                    10s
cloying-crocodile-wordpress  LoadBalancer  10.0.168.104  <pending>    80:31549/TCP,443:32728/TCP  10s
...

You can see all the objects that are necessary to run our Wordpress application in your Kubernetes cluster deployed such as pods, services, secrets etc... Furthermore, since we need a MariaDB engine to run Wordpress, Helm did also automatically deploy it as a dependency in the cluster !

As you can see inside the Wordpress's Chart documentation you can override some values such as the image, the database name or the SMTP server for example.

You just have to use the --set option during the install command, like so :

helm install --name my-wordpress \
  --set wordpressUsername=admin,wordpressPassword=password,mariadb.mariadbRootPassword=secretpassword \
    stable/wordpress

Create your own Chart

You can also create your own Chart by using the scaffolding command helm create mychart

This will create a folder which includes all the files necessary to create your own package :

β”œβ”€β”€ Chart.yaml
β”œβ”€β”€ templates
β”‚Β Β  β”œβ”€β”€ NOTES.txt
β”‚Β Β  β”œβ”€β”€ _helpers.tpl
β”‚Β Β  β”œβ”€β”€ deployment.yaml
β”‚Β Β  β”œβ”€β”€ ingress.yaml
β”‚Β Β  └── service.yaml
└── values.yaml

All the objects that you want to deploy are stored inside the templates folder in different .yaml files.

You can find more information on how to create your own chart here : https://deis.com/blog/2016/getting-started-authoring-helm-charts/

When you are done with your package, Helm provides a linting tool helm lint mychart to help you find issues in it.

If you want to deploy it into your cluster, you can run the following command from the repository folder:

helm install . --name my-custom-chart

Exercises

Exercise 1 - Deploy an official Chart : DokuWiki

From the official Chart repository you have to deploy a DokuWiki environment.

DokuWiki is a standards-compliant, simple to use wiki optimized for creating documentation. It is targeted at developer teams, workgroups, and small companies. All data is stored in plain text files, so no database is required.

Validation

We want to be able to define a custom Wiki name such as Hello MLADS at the deployment.

You should see the following web page from your deployment :

Solution

Solution (expand to see)

    helm install stable/dokuwiki --set dokuwikiWikiName="Hello MLADS"

Next Step

4 - Kubeflow