Helm - Add some dynamism to your K8s deployment
Published: 2021-03-22 15:33:45

*When we begin with Kubernetes, we are writing a lot of commands or yaml files to generate all the elements we need. But, at a time, we have a lot of similar elements to create for each service, and we don't want to spend a lot of time on it.*

So to help you on your Kubernetes deployments, you can use **Helm**.

Based on Jinja2, you can add a lot of dynamism to your deployments.

---

# First, what is Jinja?

Jinja is a templating language for python for web pages.

It can :
- display variables value dynamically

```
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
```

- repeat a specific pattern for all the elements of the list

```
{% for user in users %}
  <li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}
```

- display specific parts based on a variable value

```
{% if 'priority' in data %}
    <p>Priority: {{ data['priority'] }}</p>
{% endif %}
```
- ...

---

# Second, how to use helm?
## Setup helm
When helm is installed, you have to create your **Chart**. It will contain the next files:
- **Chart.yaml**: Will contains the chart definition
- **values.yaml**: Will contains the default input values
- **.helmignore** *optional*: Contains the file list to ignore when building a project
- **templates**: Directory which contains all your yaml files.
   - **_internal** *optional* : An optional file to create some values, based on other input values.
   - *your yaml files*: Your yaml files to generate your secrets, deployments, and more! It's here where you can use the Jinja template!

## Install chart
When your chart is ready, you can install it! It will deploy all your yaml files in the chart.

Command to install it
> helm install <release name> <path to the chart>

Then you can add a lot of options to the command
- **-f <yaml file>** : Import a yaml file to override your default values
- **-n <namespace>** : Namespace where to deploy the elements
- **--set-string <key>=<value>** : Will override a value
- ...

Go check the documentation to have the list of all the options. (https://helm.sh/docs/helm/helm_install/)

## Upgrade chart
Then you can upgrade your chart
> helm upgrade <release name> <path to the chart>

## Uninstall chart
And when you want to delete it, you can use the following command
> helm uninstall <release name>

---

# The power of helm
It's quite cool to be able to add dynamism to your installations. But sometimes, you don't want to rewrite something to install a tool on Kubernetes.

So here is [Artifact Hub](https://artifacthub.io/)!

Like Docker and its dockerhub, Helm gets its own public repo where you can find a lot of charts for a lot of tools!

*Example with grafana*
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/32i3s3iz5zh15l1leht7.PNG)

---

### Links
- Website Helm: https://helm.sh/
- Website Jinja2: https://jinja.palletsprojects.com/en/2.11.x/
- Artifact Hub: https://artifacthub.io/

If you want to go further:
- **What is Helm in Kubernetes?** by TechWorld by Nana : https://www.youtube.com/watch?v=-ykwb1d0DXU
- **What is Helm?** by IBM Cloud : https://www.youtube.com/watch?v=fy8SHvNZGeE
- **Using Helm and Kubernetes** on Baeldung : https://www.baeldung.com/kubernetes-helm

--- 

I know it's a quick show of Helm, but I hope it will help you! 😀