Journey with Helm charts

I have been working on kubernetes, docker and helm charts for quite sometime installing elasticsearch, jaeger and spark applications in kubernetes cluster. despite having been worked, never created a helm chart from the k8s files.

It is getting too much clutter despite the reduction of k8s files moving away from pods, services, deployments, ingress towards Operators. Helm charts seems inevitable to produce our product as one single deployable file with few no. of parameters.

So far i have used helm,
Just 3 steps,
1. Install helm & minikube or point to existing k8s cluster from local
2. Install Helm Repository
3. Install required application 

I use to install helm repo and install applications of required version and configuration.
 
https://hub.helm.sh/ - Wonderful helm repository with all charts required. Just like maven repository for jars.

Post getting familiar with Operators, I happen to install Operators.
https://operatorhub.io/ - Wonderful Operators repository. 

The specialty of Operators is that every application has its own Custom Resource Definition (i.e., provides its own API and plugs it under Kubectl Command line tool once it is installed in our k8s cluster) just like the local machine installation, if we are familiar with the application we can easily handle without going through Kubernetes API.

Life cycle management in Operators is very easy. Helm can also handle lifecycle of application but it can mostly uninstall and install or do compatible upgrades, otherwise for incompatible upgrades & downgrades the custom operators provided by application developers will surpass. Helm can manage Operator life cycle which is going to see less changes unlike real applications.

Today I happen to create my own HELM chart,

Raw Yaml Chart

To create a simple chart, I followed the below guide.

$ helm create mychart
Creating mychart
I remove all the values and templates. I just dropped all my yaml files into templates folder and made a dry run

$ helm install blahblah --dry-run --deploy ./mychart -n somenamespace
All the yaml files just raw once could be installed now with helm command. I only did dry run to check what will be the output. Finished, my chart was ready :)

Templating

I tried to replace only one repeated string in the value and made a template out of it.


template.yaml  (random yaml file in templates)

key: {{ .Values.name }}
values.yaml

name: blahblah
$ helm install blahblah --dry-run --deploy ./mychart -n somenamespace
Done. The value replaced template returned out of the dry run command. 

Control Structures
Now I was in requirement to loop to generate multiple yaml syntaxes. Before that I had conditional execution requirement, I used if and if not constructs in template. 

Looping was little tough, but the below page helped. Initially i was not able to get any clue as helm command did not throw any error pointing the issue what went wrong with the template, it is little frustrating. I came over the frustration by creating another helm chart to try out example given in the link. I did missed out something called as SCOPE of the variables in template with and without $


Loops and Object access with range & with template syntax introduces something called Local Scope, within the envelope of code which the syntax cover. In order to access the Global values present in Values.yaml, we are supposed to make use of $, a way to access global scope.

Everything fell into place

Almost 4 to 5 years ago i used mustache js https://github.com/janl/mustache.js/. Go templates are not very different from it. I happen to used it along with backbone js and angular 1.0.

I have also used angular 2.0, the scoping part of go templates is same it is present in angular.

String manipulations that are required to use in templates of helm are available in below link. I used something called kebabcase :D, the name refers to food dish and someone had named it for purpose and its funny.

Journey Continues

My sojourn to helm world has just started. Below are some interesting spots in helm to visit.

https://helm.sh/docs/topics/charts/ - Lot many things to learn about dependencies in Charts.

https://helm.sh/docs/topics/charts_hooks/ - Just like installation phase of maven, we have phases like pre-install, pre-upgrade, pre-rollback and its post counterpart and test. Hooks available to perform some operation.

https://helm.sh/docs/topics/chart_tests/ - A bit of integration testing, setup, run and disassemble.

https://helm.sh/docs/topics/library_charts/ - Refactoring charts with libraries

https://helm.sh/docs/topics/provenance/ - To transfer artifact securely and with integrity without any loss.


Experimental supports

https://helm.sh/docs/topics/registries/ - OCI instead of tar or zip :) Many people including java is moving away from zips (for jars) towards images.

System

Advanced Users Options

K8S - Many Platforms

User Control

Plugins

SQL Storage

hmmmm... And many many more, an endless list. I am done for the day. 

Comments

Popular posts from this blog

JavaScript Debut as a Full Fledged Language for Production in the Age of Cloud, Big Data and IoT

Make Raspberry Pi Independent of Peripheral Devices & Connector Cables

Following Java, Exploring Projects JIGSAW and KULLA - Intro