Creating a Helm chart to deploy a Flask web-app on the Kubernetes cluster
Describing a Helm chart
Helm has a certain structure when you create a new chart. To create, run “helm create YOUR-CHART-NAME”. Once this is created, the directory structure should look like this:
- .helmignore: This holds all the files to ignore when packaging the chart. Similar to .gitignore, if you are familiar with git.
- Chart.yaml: This is where you put all the information about the chart you are packaging. So, for example, your version number, etc. This is where you will put all those details.
- Values.yaml: This is where you define all the values you want to inject into your templates. If you are familiar with terraform, think of this as helms variable.tf file.
- Charts: This is where you store other charts that your chart depends on. You might be calling another chart that your chart needs to function properly.
- Templates: This folder is where you put the actual manifest you are deploying with the chart. For example, you might be deploying an nginx deployment that needs a service, configmap, and secrets. You will have your deployment.yaml, service.yaml, config.yaml and secrets.yaml all in the template dir. They will all get their values from values.yaml from above.
Installing Helm and configuring Helm Charts
Ready to use Helm? Installing and configuring Helm for your K8S cluster is a very quick and straightforward process — there are multiple versions of Helm that can be installed (v1/v2 and most recently v3), all of which can be configured to your organization’s needs. Check out the getting started page for instructions on downloading and installing Helm.
Beginning your first Helm chart is as simple as installing some charts from the stable repository, which is available on GitHub. The Helm stable repository is a collection of curated applications ready to be deployed into your cluster.
Helm users can write their own charts or can obtain charts from the stable repository:
If you want to write your own Helm Charts for your applications, Helm provides a simple Developer’s Guide for getting started.
We will create our own helm chart to deploy a basic flask website on Kubernetes.
I am creating a Dockerfile to upload my docker image on the docker hub so that it can be pushed in anywhere.
Now we can see that my image is created locally and now I have uploaded it to the dockerhub.
Now we would configure our helm chart.
We would download and extract the helm version 3.5.2
And add the helm executable file to /usr/bin to activate the service.
Now I have created a Chart.yaml file which would define our version and Chart description.
In the template file we would create the deployment yaml and service yaml files according to our needs.
All the variables will be defined in the values yaml file.
Now that our setup is done we would install our package/chart via helm install command.
We can check that our deploy and svc are running.
Now we can access our website anywhere in the world if our port is attached to the public IP.