Create Helm chart and publish on ArtifactHub

Urvishtalaviya
4 min readApr 9, 2021

This article will show you how to create a helm chart for Kubernetes and how to publish it on the ArtifactHub repository. Before getting into the Helm check out this article for how to create a customs container image with Docker

Helm chart

Helm charts are nothing but packages that help to deploy complex environments on the Kubernetes cluster with one click. A Helm chart created with a YAML language creates YAML files according to the requirements with some structure and you good to go. Before the creating helm chart installs helm software from https://helm.sh/ according to your Operating System. In my case, I will use Amazon Linux because my k8s cluster is deployed on AWS.

helm version

Use the above command to check the version of Helm. For creating a Helm chart, follow these simple steps:

First, let’s create a workspace so that all the code we can put into it

mkdir helm-chart/
cd helm-chart/

Step 1: Create a folder for the helm chart

mkdir ml-helm-chart/
cd ml-helm-chart/

This folder will contain all the necessary files for the Helm chart and whatever name you give to the folder would be the name of the chart.

Step 2: Create Chart.yaml file

Chart.yaml file has metadata about the helm chart, without it, helm can not identify the helm chart. Create the file with the below-given instructions

apiVersion: v2
name: machine-learning-chart
description: This app will predict the passanger will service or not from titanic incident.
type: application
version: 0.1.0
appVersion: "1.16.0"

You can give a version and appVersion according to your convince.

Step 3: Create templates folder and resource files

First, create a folder named templates, that contains all the resource spec files. In this example, we would need two resources: Deployment and Service.

mkdir templates/
cd templates/

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: machine-learning-deployment
labels:
app: my-deployment
spec:
replicas: {{ .Values.replicaCount}}
selector:
matchLabels:
app: my-deployment
template:
metadata:
labels:
app: my-deployment
spec:
containers:
- name: my-container
image: urvish667/machine-learning:v1

For this example, I have used an image called urvish667/machine-learning:v1 that we had created in the previous blog. You will find {{ .Values.<variable-name> }}, these all are the variables and the values come from the file called values.yaml file which we see next in this blog.

service.yaml

apiVersion: v1
kind: Service
metadata:
name: machine-learning-service
spec:
ports:
- nodePort: {{ .Values.port }}
port: 5000
protocol: TCP
targetPort: 5000
selector:
app: my-deployment
type: NodePort

service.yaml file creates the service for exposing the deployment to the public world.

Step 4: Create values.yaml file

replicaCount: 3
port: 30000

This file contains variables that we can use in the resource files for better management. Create this file outside of the templates folder.

Now, your folder would look like this:

Your Helm chart is almost ready. Let’s check it by installing it on the k8s cluster.

Step 5: Install the Helm chart

helm install <name-for-app> <chart-name>/

For instance, “helm install myapp1 ml-helm-chart/” in my case.

Listing the helm chart

Let’s check all the resources

resources

Application output

ArtifactHub.io

Artifact Hub is a web-based application that enables finding, installing, and publishing packages and configurations for CNCF projects, including publicly available distributed charts Helm charts. It is a Cloud Native Computing Foundation sandbox project

For publishing the chart on ArtifactHub, follow these steps:

Step 1: Create a charts/ folder

This charts/ folder will create in the workspace where we had created the chart.

mkdir charts/
cd charts/

Step 2: Create the package from the chart

helm package <chart-name>/

In this case, helm package ml-helm-chart/ and output would the tar file

Step 3: Create an index.yaml file

index.yaml file maintains all the chart information. The below-given command will create it for us.

helm repo index <chart-name>/

Now, almost all the things are ready.

Step 4: Upload chart file to GitHub and make Github pages

Upload the chart file to the Github repository and go to the settings, move to the GitHub pages, and select branch as main/master whatever you had created, and also select the destination folder then save. You get the link like this https://urvish667.github.io/helm-chart/

Step 5: Add package on ArtifactHub

Now, go to the control panel of your account and click on add for adding the helm chart. Give a name to the helm chart and provide the GitHub page URL with the location of your chart. That’s it. You have done it.

Congrats!! you have done it…

Thanks for reading!! Hope you find it informative.

--

--

Urvishtalaviya

Competitive Programmer | Machine Learning Enthusiastic | Bigdata Enthusiastic