What is Helm?
Helm helps you manage Kubernetes applications — Helm Charts help you define, install, and upgrade even the most complex Kubernetes application.
Helm is widely known as “the package manager for Kubernetes”. Although it presents itself like this, its scope goes way beyond that of a simple package manager. However, let’s start at the beginning.
Helm Chart
The path Helm took to solve this issue was to create Helm Charts. Each chart is a bundle with one or more Kubernetes manifests — a chart can have child charts and dependent charts as well.
This means that Helm installs the whole dependency tree of a project if you run the install command for the top-level chart. You just a single command to install your entire application, instead of listing the files to install via kubectl
.
Charts allow you to version your manifest files too, just like we do with Node.js or any other package. This lets you install specific chart versions, which means keeping specific configurations for your infrastructure in the form of code.
Why helm?
Helm also keeps a release history of all deployed charts, so you can go back to a previous release if something went wrong.
Helm supports Kubernetes natively, which means you don’t have to write any complex syntax files or anything to start using Helm. Just drop your template files into a new chart and you’re good to go.
How Does Helm Work?
Helm and Kubernetes work like a client/server application. The Helm client pushes resources to the Kubernetes cluster. The server-side depends on the version: Helm 2 uses Tiller while Helm 3 got rid of Tiller and entirely relies on the Kubernetes API.
Prerequisites:
1. Kubernetes cluster should be configured
It is often advisable to install the most compatible version of the Kubernetes as supported by Helm. We should also install and configure the Kubernetes command-line tool kubectl, enabling us to work with our cluster efficiently.
2. Helm should be installed
Installing kubernetes
So, First we are going to install kubernetes
We are going to install from command line program kubectl installed on your Windows 10 computer and configured to work with a Kubernetes Cluster. The easiest way to do this is to install using the Windows package manager Chocolatey, choco install kubernetes-cli.
Or you can use the below link to configure k8s on aws clould and perform the practical there also
Installing Helm
There are several ways to install Helm that are neatly described on the official install page on Helm. The quickest way to install helm on Windows is using Chocolaty, a package manager for Windows platforms.
Using Chocolaty, it’s a simple one-line command to install Helm:
choco install kubernetes-helm
This installs the Helm client locally. This also provides us with the Helm command-line tool that we’ll use to work with Helm in this tutorial.
Before proceeding further, we should ensure that the Kubernetes cluster is running and accessible using the kubectl command:
kubectl cluster-info
We could initialize Helm through the Helm CLI using the command:
helm init
If you are starting with Helm 3, since there is no more Tiller server, it’s unnecessary to initialize Helm. In fact, this command has been removed. Consequently, the Helm state is created automatically when required.
Let’s start
Let’s quickly see the directory structure created for us:
helmweb /
Chart.yaml
values.yaml
templates /
charts /
.helmignore
Let’s understand the relevance of these files and folders created for us:
- Chart.yaml: This is the main file that contains the description of our chart
- values.yaml: this is the file that contains the default values for our chart
- templates: This is the directory where Kubernetes resources are defined as templates
- charts: This is an optional directory that may contain sub-charts
- .helmignore: This is where we can define patterns to ignore when packaging (similar in concept to .gitignore)
Creating a Chart
Create one directory and generally, the name of the package (chart) will be equal to the directory name.
mkdir helmweb
The next step, of course, would be to create a new file with a name say chart.yaml:
- This is where you’ll put the information related to your chart. That includes the chart version, name, and description so you can find it if you publish it on an open repository. Also in this file you’ll be able to set external dependencies using the
dependencies
key.
# Chart.yaml
apiVersion: v1
name: helmweb
description: A Helm chart for Kubernetes for launching webserver
type: application
version: 0.0.5
appVersion: 1.1.0
Creating Template
# templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: mydeploy
name: mydeploy
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: mydeploy
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: mydeploy
spec:
containers:
- image: suman526/webpage_helm
name: webpage
resources: {}
status: {}
Now next file in the template folder is service.yaml
# helmweb/templates/service.yaml
apiVersion: v1
kind: Servicemetadata:
creationTimestamp: null
labels:
app: mysvc
name: mysvc
spec:
ports:
- name: 80-80
port: {{ .Values.myservice.port }}
protocol: TCP
targetPort: 80
selector:
app: mysvc
type: {{ .Values.myservice.type }}
status: loadBalancer: {}
Creating Values files
Like we saw before, this is the file that contains defaults for variables.
replicaCount: 3
myservice:
type: Nodeport
port: 8080
Now, our Helm chart ready!
We have to create a package for helm chart.
mkdir charts/
Now, run the following command to packages the chart and store it inside the charts/ directory.
helm package helmweb -d charts/
After successfully packaged chart and saved create an index.yaml file
Creating an index.yaml file
For every Helm repository, we must require an index.yaml file. The index.yaml file contains the information about the chart that is present inside the current repository/directory.
helm repo index charts/apiVersion: v1
entries:
myweb:
- apiVersion: v1
appVersion: 1.1.0
created: "2022-06-09T17:23:26.9461245+05:30"
description: A Helm chart for Kubernetes for launching webserver
digest: 1db457438057de8db20ed35f37fcb5d1dd997401a421673c3f71a94e39f519a3
name: helmweb
urls:
- myweb-0.0.5.tgz
version: 0.0.5
generated: "2022-06-09T17:23:26.9461245+05:30"
Push the chart to the GitHub public repository
Here, push the packaged chart as well as the chart source code to the Github repository
For publishing the Helm chart on artifacthub.io/, we must require a URL where we had hosted our helm chart. One of the free and easy ways to host the charts is using GitHub pages. So, we will first host our charts using GitHub pages.
Publish Helm chart to ArtifactHub
Go to the https://artifacthub.io/ and login to your account.
Click on add repository.
If the URL you had provided to the charts is correct then it will create a Helm repository.
For installing any helm chart, we first required to add the repository in which that chart is present.
Now, we can install our chart from this repository. As you known, the name of our chart is myweb.
helm install web httpd-webserver/helmweb
Finally, we have successfully published our helm chart.
Thank You for Reading!!!!!😀