Complete guide for creating and publishing Helm chart

Ankush Chavan
6 min readMar 26, 2021

--

Kubernetes is widely known for its ability to orchestrate containers. With the help of Kubernetes, we can deploy our application for achieving high availability and agility. Usually, we write configuration files for creating the resources in Kubernetes, and as the project progresses it will become hard to manage all of these files and versions well. So, for managing these configuration files, we are required to use some management tools, and here the use of Helm comes into the picture.

Helm is a package manager for Kubernetes that helps in deploying the applications, managing the versions of application resources, and packaging the application files. Helm deploys charts. A chart is basically a packaged application.

In this article, we will learn to create a Helm chart for an httpd webserver, packing this chart using Helm and publishing the Helm chart on https://artifacthub.io/ and some more things.

So, let us start.

Prerequisites:

  1. Kubernetes cluster should be configured
  2. Helm should be installed
  3. Active GitHub account

Step 1: Creating a Helm chart for an httpd webserver

Create one directory and generally, the name of the package (chart) will be equal to the directory name.

$ mkdir myweb

Inside this folder, we need to create one file named Chart.yaml. This Chart.yaml is the configuration file for the chart.

$ cd myweb
$ touch Chart.yaml

Inside the Chart.yaml file we will write the details of the chart like name, version, description, appVersion, etc.

Creating resource files:

Resources in the chart are known as templates. So, to manage the resources, we have to create a folder named templates.

$ cd myweb/
$ mkdir templates

Now, we can write all of our resource files inside this templates directory.

If you look at the above configuration files, they are static. Here, we want to control certain things like a number of replicas. For achieving this, we have to make the template files dynamic.

For making templates files dynamic. we have to use variables. This is known as parameterized.

We have to create a file named values.yaml and inside this file, we can declare all of the variables. When the helm installs the chart, it will automatically get the variable values from values.yaml file.

$ cd myweb/
$ touch values.yaml

In the above file, we are defining the variables for replica count, type of service, and port number of the service. This provides us the flexibility that at the time of chart installation we can set the values of these variables. But how our resource configuration files come to know these values?

For getting the values from values.yaml file into the resource configuration(template) files, we have to use a Jinja templating format.

Now, we have our Helm chart ready.

Step 2: Packaging resources inside the Helm chart

We have our helm chart ready inside the myweb/ directory, but we can’t publish it as it is. Firstly, we have to create a package for this helm chart.

Create one directory named charts.

$ mkdir charts/

Now, run the following command to packages the chart and store it inside the charts/ directory.

$ helm package myweb -d charts/

You can see on tarball package is created inside charts/ directory.

Step 3: 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.

For generating index.yaml file inside charts/ directory, run following command.

$ helm repo index charts/

You can see an index.yaml file generated with the details of the chart.

Step 4: Push the chart to the GitHub public repository

Here, I will push the packaged chart as well as the chart source code to the Github repository, but you can push only the chart/ folder to the Github as well.

GitHub Repository for this chart:

Step 5: Hosting the chart with GitHub pages

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.

Go to the setting of the repository and go all the way down to the Github pages section.

Select the branch and directory for the charts and save it.

This will provides us one URL where our charts are hosted.

As we had placed our charts inside charts/ directory, the actual URL for the charts is look like this — https://cankush625.github.io/httpd-webserver-helm-chart/charts/

Step 6: Publishing the Helm chart to ArtifactHub

Go to the https://artifacthub.io/ and login to your account.

Click on add repository.

Select the kind as Helm charts, provide a name to the repository and enter the URL to the charts as we discussed in Step 5.

Click on add.

If the URL you had provided to the charts is correct then it will create a Helm repository.

So, we had successfully published our own Helm chart to the artifacthub.io

Step 7: Using our Helm chart from ArtifactHub

First of all, run following command to check if we have any helm repositories added.

$ helm repo list

For installing any helm chart, we first required to add the repository in which that chart is present. As our chart is present in https://cankush625.github.io/httpd-webserver-helm-chart/charts/ repository, lets add it to the local helm.

$ helm repo add httpd-webserver https://cankush625.github.io/httpd-webserver-helm-chart/charts/
$ helm repo list

Now, we can install our chart from this repository. As you known, the name of our chart is myweb.

$ helm install web httpd-webserver/myweb
$ helm list

Finally, we had successfully published our helm chart.

Now, you may think, how I can mark my helm repository as a Verified Publisher?
Here is a bonus step for you…

Bonus step:

Label your helm repository as Verified Publisher

For labeling your helm repository as a Verified Publisher, you need to add one metadata file in the charts/ directory. The name of the file should be artifacthub-repo.yaml.

$ touch charts/artifacthub-repo.yaml

The repositoryID is the id of the helm repository we created on https://artifacthub.io/

Now, commit these changes to the GitHub.

After few minutes, visit to the https://artifacthub.io/ and you will see an Verified Publisher label attached to your helm repository.

I would love to know if you find this article helpful.

For any help or suggestions connect with me on Twitter at @TheNameIsAnkush or find me on LinkedIn.

Thank you!

--

--