A general introduction to Helm and a practical exercise to create a Helm Chart
Hey Techies…👋
In this session , we’re going to see an overview of Helm and how to create a Helm Chart..
Before going to the hands-on lab , let’s have some basic idea on Helm and helm Chart
What is Helm
Helm is a package manager for Kubernetes. Helm is the K8s equivalent of yum or apt. Helm deploys charts, which you can think of as a packaged application. It is a collection of all your versioned, pre-configured application resources which can be deployed as one unit. You can then deploy another version of the chart with a different set of configuration.
What is Helm Chart
Helm Charts are simply Kubernetes YAML manifests combined into a single package that can be advertised to your Kubernetes clusters.Creating a Helm chart for your application simplifies reproducible deployments into a Kubernetes cluster. Users can install the whole chart with one command, instead of manually applying individual component manifests with kubectl.
Goal of Helm
Helm is an open-source project which was originally created by DeisLabs and donated to CNCF, which now maintains it. The original goal of Helm was to provide users with a better way to manage all the Kubernetes YAML files we create on Kubernetes projects.
Benefits of Helm
- Boosts productivity
- Reduces duplication & complexity of deployments
- Ability to leverage Kubernetes with a single CLI command
- Implementation of cloud-native applications
- Ability to re-use Helm charts across multiple environments
The procedures that we will follow for this practical activity are as follows:
- Prerequisites — GKE
- Check all nodes are in steady state
- Download the helm file
- Create Helm
- Change the service type
- Install Helm chart
- Verify application
- Delete Helm chart
⭐⭐⭐ Let’s get started……………… ⭐⭐⭐
1 — Prerequisites — GKE — Create Google Kubernete cluster engine in GCP
Search for Kubernetes Engine in Google Cloud console and create a cluster.
Pick Standard Cluster and use the default options when creating. The cluster is definitely enabled, as seen by the green tick mark in the image below.
2 — Check all nodes are in steady state
Check that all nodes are in the ready status by connecting to the command-line access of GKE.
kubectl get nodes
3 — Download the helm file
Now, by executing the command below, we’ll download the helm file:
wget https://get.helm.sh/helm-v3.4.1-linux-amd64.tar.gz
As we can see it is a compressed file, extract it using below command and copy it into location — /usr/local/bin
tar xvf helm-v3.4.1-linux-amd64.tar.gz
sudo mv linux-amd64/helm /usr/local/bin
The following essential step is to verify the Helm version that we installed:
helm version
4 — Create Helm
Now we can begin creating a Helm, by using the below command in our working directory:
helm create demo-helm
We can verify the helm project is created by running below command, a directory should be created with the name of demo-helm
ls -ltr
We can also check the tree structure of demo-helm like below:
tree demo-helm
Therefore, we will automatically receive all of those yaml files once we run the “helm create” command to start a Helm.
There are two top-level files and two supplementary sub-directories. Here’s what each resource is used for:
- Chart.yaml —The manifest for the Helm chart specifies the metadata’s name and version.
- values.yaml — The default values for variables that we can use as references in our chart are stored in this file. When we install the chart, we have the option to use CLI flags to override the settings that have been set here.
- templates — The templates directory contains our chart’s Kubernetes object manifests. Installing the chart will apply all these manifests to our cluster. Any valid Kubernetes YAML manifest can be placed here; we can also use extra functionality, such as references to variables defined in our values.yaml file.
- charts — This Helm chart depends on other Helm charts that are stored in the charts directory. It is utilised to set up complicated parent-child chart relationships.
Add a Chart Repository
helm repo add stable https://charts.helm.sh/stable
But what does that stable repository contain? List out the contents with the command:
helm search repo stable
Before installing a chart from the Helm stable repository. First let’s update everything with the command:
helm repo update
Searches the repositories that you have added to your local helm client (with helm repo add). This search is done over local data, and no public network connection is needed.
Searches the Artifact Hub, which lists helm charts from dozens of different repositories.
helm search repo
helm repo add
helm search hub
If we need to search the httpd packages , then run the below command:
helm search hub httpd
It will list out the links and click on any of th links and install that particular helm chart:
Here I selected this link — https://artifacthub.io/packages/helm/myweb/myweb , we will get a new page and click on install in it. So we will get a page like below and execute both commands respectively :
helm repo add myweb https://raw.githubusercontent.com/MasterCloudApps/3.2.Contenedores-y-orquestadores/master/k8s/helm/ejem3/charts/
helm install my-myweb myweb/myweb --version 0.0.5
Also we can create helm chart as mentioned in step 6 below after adding repo
5 — Change the service type
The values.yaml file contains a service portion contains service type and port. Here we could see the ClusterIP and port 80 in the screenshot below, which needs to be changed to NodePort.
Because we should be able to access the service from outside the Kubernetes cluster after installing and running the Helm chart, Hence we are modifying the service type as NodePort. If service type is ClusterIP , we can only access the service within the cluster.
vim values.yaml
So we have changed the service type using vim command and saved it.
We can also take the service type as LoadBalnacer , so we will get the external ip and we can access the deployed application through it.
6 — Install Helm chart
“demo-helmchart” is the custom name which we’re going to deploy inside the kubernetes cluster and “demo-helm” is the directory name of helm we created :
helm install demo-helmchart demo-helm
Let’s verify the helm-charts we’re running inside our kubernetes cluster by running below command:
helm list
7 — Verify application
We can verify the application by running this command — “ kubectl get all -o wide”
To print the services running in the kubernetes cluster , use below command:
kubectl get svc
Take the IP and port that we deployed the helm chart (port from the above screenshot ):
And paste into the browser as follows:
172.18.0.1:31825
Here is the output…..
8 — Delete Helm chart
Do not forget to uninstall the helm chart once the learning activity is completed:
helm uninstall demo-helmchart
⭐⭐⭐ Enjoy your learning….!!! ⭐⭐⭐