DEV Community

Cover image for How to Package and Publish Your Custom Helm Charts- A Hands-On Tutorial
Aman Pathak
Aman Pathak

Posted on

How to Package and Publish Your Custom Helm Charts- A Hands-On Tutorial

Image description

Introduction

In this guide, we will explore how to package and publish multiple Helm charts in a single GitHub repository. We’ll deploy two distinct applications — a Go-based portfolio website and the classic Tetris game — on a Kubernetes cluster using Helm. By the end, you will have learned how to create, package, and publish Helm charts on GitHub and deploy them in a Kubernetes environment.

Objective

The objective of this tutorial is to help you understand:

  1. How to create multiple Helm charts.
  2. How to package and publish those charts on a GitHub repository.
  3. How to install and run those applications on Kubernetes using Helm.

Pre-requisites

Before starting, ensure you have the following tools installed:

kubectl for interacting with Kubernetes clusters.
Helm for managing Kubernetes applications.
Minikube for local Kubernetes cluster setup (optional).
A public GitHub repository to publish your Helm charts.
Repository for this Hands-On Project- https://github.com/AmanPathak-DevOps/Helm-Charts/tree/master

Hands-On Guide 👐📘

Create a new GitHub repository

Note: It is required to keep your repository public to publish the helm charts

Image description

I am cloning the same repo on my EC2 machine. You can do the same on your local machine with the above-required tool installation.

Image description

We are going to create two different charts. So we can learn how to package multiple charts in one repo and publish them on Git Hub as well. The first chart has a portfolio website in Go Lang and the second chart is a game known as Tetris. You don’t need to follow the Kubernetes manifest file if you don’t want to.

To create a first helm chart, run the below command

helm create go-portfolio-app
Enter fullscreen mode Exit fullscreen mode

Image description

We already have our own Manifest file content and values file. So, empty the templates folder and remove the values.yaml file

Image description

Now, create a deployment.yaml file and service.yaml file then copy the content from below.

namespace.yaml

apiVersion: v1
kind: Namespace
metadata: 
    name: go-app
Enter fullscreen mode Exit fullscreen mode

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: go-portfolio
  namespace: go-app
  labels:
    role: go-portfolio
    env: dev
spec:
  replicas: {{ .Values.replicaCount }}  # Use replica count from values.yaml
  selector:
    matchLabels:
      role: go-portfolio
  template:
    metadata:
      labels:
        role: go-portfolio
    spec:
      containers:
      - name: go-portfolio
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"  # Pull image and tag from values.yaml
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        ports:
        - containerPort: 8080
        resources:
          requests:
            memory: "256Mi"
            cpu: "500m"
          limits:
            memory: "512Mi"
            cpu: "1"
Enter fullscreen mode Exit fullscreen mode

service.yaml

apiVersion: v1
kind: Service
metadata: 
  name: go-portfolio-svc
  namespace: go-app
spec: 
  ports: 
  - port: 8080
    targetPort: 8080
  type: ClusterIP
  selector: 
    role: go-portfolio
Enter fullscreen mode Exit fullscreen mode

values.yaml

replicaCount: 1

image:
  repository: avian19/go-port
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: "10201891038"
Enter fullscreen mode Exit fullscreen mode

Hope you have added the above YAML code in your respective files.

Image description

Before going to package your helm chart, you can validate whether the helm chart is correct or not by deploying it.

helm install <chart-name> <chart-dir>
Enter fullscreen mode Exit fullscreen mode

Image description

The Go App is running fine. So, don’t forget to uninstall it

helm uninstall <chart-name>
Enter fullscreen mode Exit fullscreen mode

Image description

Now, we are ready to package our helm chart.

Go to the GitHub root directory and check the status

I am pushing my changes to the master branch(to keep track) which is not required in the process of packaging and publishing the helm chart.

Image description

To Package your Helm Chart and publish it, the gh-pages branch is required in our GitHub Repo. So, create a branch called gh-pages

git checkout -b gh-pages
Enter fullscreen mode Exit fullscreen mode

Image description

Once, the branch gets created. We need to create a package of our go-portfolio-app.

To generate the package, you need to run the below command which will generate a file having tgz extension.

Note: The branch will be master as it contains the Chart.yaml file

helm package <chart-name(dir)>
Enter fullscreen mode Exit fullscreen mode

Image description

So, we packaged our helm chart. Now, we are ready to publish it.

To publish, we need to create an index.yaml file that keeps track of all the packaged helm charts whenever you install them.

So, create an index.yaml file at the same place

touch index.yaml
Enter fullscreen mode Exit fullscreen mode

Image description

As you can see, the index.yaml file did not have any content. But now, we need to generate the index file based on the charts present in our repository which is go-portfolio-app.

To generate the index.yaml file, run the below command

helm repo index <dir-where-tgz-file-located>
Enter fullscreen mode Exit fullscreen mode

Image description

Now, Index.yaml is not empty as it holds the chart name go-portfolio-app

Finally, we need to push our gh-pages branch changes to GitHub.

Image description

As soon as you push your changes to the GitHub repo.

Go to the browser and check the GitHub repository, you will see there will a GitHub Actions workflow getting triggered in Orange color.

Image description

Once you click on it you will see the deployment gets completed. But where is it deployed?

Image description

To check the deployed place,

Go to the Settings of your GitHub repository and navigate to Pages where we are hosting our helm charts

As you can see in the below snippet, Your site is live at https://amanpathak-devops.github.io/Helm-Charts/. This will be our URL to deploy Helm charts on any Kubernetes Cluster.

Image description

Now, add the helm chart repo using the below command

helm repo add aman-devops https://amanpathak-devops.github.io/Helm-Charts/
Enter fullscreen mode Exit fullscreen mode

Image description

Now, we are ready to install our helm chart through the helm install command

helm install go-app aman-devops/go-portfolio-app

Enter fullscreen mode Exit fullscreen mode

Image description

You can run the below command to list the created Kubernetes resources through the helm chart

kubectl get all -n go-app
Enter fullscreen mode Exit fullscreen mode

Image description

Run the below command to access your application

kubectl port-forward svc/tetris-service -n tetris 3000:3000
Enter fullscreen mode Exit fullscreen mode

To access your application on the browser, you can hit the showing link in your browser

Image description

If you are using EC2 Server and want to access applications in your browser then, the kubectl port-forward command won’t be enough. To access your browser, run one more command on your local machine it is almost the same command as ssh does.

ssh -L 8080:localhost:8080 <ec2-user>@<public-ip> -i <Pem-file>
Enter fullscreen mode Exit fullscreen mode

Image description

We have successfully packaged and published our first Helm chart. If you feel confident with this process, you can go ahead and exit this blog or document. I hope you found something new to learn. However, if you’re interested in learning how to create multiple charts within a single GitHub repository, I invite you to continue with me in this guide.

Let’s go ahead and create another chart, which should be quick if you already grasp the process!

So, I switched back to my master branch in my GitHub repository

git switch master
Enter fullscreen mode Exit fullscreen mode

Image description

Create a new helm chart named tetris-game

helm create tetris-game
Enter fullscreen mode Exit fullscreen mode

Image description

Empty the templates folder and remove the values.yaml file

Image description

Now, add your YAML files given below

namespace.yaml

apiVersion: v1
kind: Namespace
metadata: 
    name: tetris
Enter fullscreen mode Exit fullscreen mode

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tetris
  namespace: tetris
spec:
  replicas: 3
  selector:
    matchLabels:
      app: tetris
  template:
    metadata:
      labels:
        app: tetris
    spec:
      containers:
      - name: tetris
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        ports:
        - containerPort: 3000
Enter fullscreen mode Exit fullscreen mode

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: tetris-service
  namespace: tetris
spec:
  selector:
    app: tetris
  ports:
  - protocol: TCP
    port: 3000
    targetPort: 3000
  type: ClusterIP
Enter fullscreen mode Exit fullscreen mode

values.yaml

replicaCount: 1

image:
  repository: avian19/tetrisv2
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: "1"
Enter fullscreen mode Exit fullscreen mode

Image description

Before going to package your helm chart, you can validate whether the helm chart is correct or not by deploying it.

helm install <chart-name> <chart-dir>
Enter fullscreen mode Exit fullscreen mode

Image description

The Tetris App is running fine. So, don’t forget to uninstall it

helm uninstall <chart-name>
Enter fullscreen mode Exit fullscreen mode

Image description

Now, we are ready to package our helm chart.

Go to the GitHub root directory and check the status

I am pushing my changes to the master branch(to keep track) which is not required in the process of packaging and publishing the helm chart.

Image description

Package the Tetris application by running the below command on the master branch

helm package <chart-name(dir)>
Enter fullscreen mode Exit fullscreen mode

Image description

Now, switch to gh-pages to package the helm chart and publish it

git switch gh-pages

Enter fullscreen mode Exit fullscreen mode

Image description

As you can see in the below snippet, the index.yaml file has a go-app chart configuration. Now, we need to update the index file to have the Tetris app configuration.

Image description

Run the below command to update the index file for the Tetris app

helm repo index <dir-where-tgz-file-located>
Enter fullscreen mode Exit fullscreen mode

Image description

Now, Index.yaml contains the configuration for chart tetris.

So we can push our gh-pages branch changes to GitHub.

Image description

As soon as you push your changes to the GitHub repo.

Go to the browser and check the GitHub repository, you will see there will a GitHub Actions workflow getting triggered in Orange color.

Image description

You can check the process of deployments by clicking on the Orange icon

Image description

You can also go to Actions to view the GitHub workflow

Image description

Now, when you are trying to install the Tetris app you might get errors as the old chart doesn’t have Tetris application configuration including index.yaml file.

Image description

Before installing the Tetris app, we need to update our helm chart

helm repo update

Enter fullscreen mode Exit fullscreen mode

Now, we are ready to install our helm chart through the helm install command

helm install tetris aman-devops/tetris-game
Enter fullscreen mode Exit fullscreen mode

Image description

You can run the below command to list the created Kubernetes resources through the helm chart

kubectl get all -n tetris
Enter fullscreen mode Exit fullscreen mode

Image description

Run the below command to access your application

kubectl port-forward svc/tetris-service -n tetris 3000:3000
Enter fullscreen mode Exit fullscreen mode

Image description

To access your application on the browser, you can hit the showing link in your browser

Image description

Enjoy the Game!

Image description

If you are using EC2 Server and want to access applications in your browser then, the kubectl port-forward command won’t be enough. To access your browser, run one more command on your local machine it is almost the same command as ssh does.

ssh -L 3000:localhost:3000 <ec2-user>@<public-ip> -i <Pem-file>
Enter fullscreen mode Exit fullscreen mode

Image description

That’s it for today. I hope you learned something new today.

Conclusion

By the end of this guide, you successfully packaged, published, and deployed two different applications using Helm charts in a Kubernetes environment. You’ve also learned how to manage multiple charts within a single GitHub repository. With this foundation, you can now apply the same process to other applications or scale your deployment strategies further!

Support my work-
https://www.buymeacoffee.com/aman.pathak

Stay connected on LinkedIn: https://www.linkedin.com/in/aman-devops/

Stay up-to-date with GitHub: https://github.com/AmanPathak-DevOps

Want to discuss trending technologies in DevOps & Cloud
Join the Discord Server- https://discord.gg/jdzF8kTtw2

Feel free to reach out to me, if you have any other queries.

Happy Learning!

Top comments (0)