How to host Helm chart repository on GitHub
In this post, we’ll create fully automated build pipeline to host a repository for Helm charts using GitHub Pages and GitHub Actions. Also, we’ll use some of the tools to ensure our charts are high quality.
What are Helm and Helm chart?
Helm is a package manager for Kubernetes and helps to manage Kubernetes applications. And helm chart repository is an HTTP server that houses an index.yaml file and optionally some packaged charts.
Github Pages?
We can create a chart repository using GitHub Pages. It allows us to serve static web pages. All we need is to host a single index.yaml file along with a bunch of .tgz files.
Let's start by creating a new git repo in the Github account.
Though it’s an empty repo, let’s just clone it for now:
git clone https://github.com/anup1384/helm-charts.git
First, need to create a gh-pages
branch in your repository and run the following:
git checkout --orphan gh-pages
git rm -rf .
git commit -m "Initial commit" --allow-empty
git push
Once you’ve done that, you need to enable GitHub Pages in your repository. Go to the settings page on your repository and set the source branch to the gh-pages
the branch you just created.
Now you’ve configured GitHub Pages, it will act as your Helm repository. Next, you need to configure GitHub Actions to publish there.
GitHub Actions
We’re going to use GitHub Actions to create two workflows: one for pull requests, and one for commits to master. Pull request workflow will deal with Linting, Testing, and validating charts using a collection of automated tooling and against schemas generated from the Kubernetes OpenAPI specification. For chart Testing to installing Helm charts on a Kubernetes cluster GitHub Actions runner use Kubernetes in Docker (KIND) cluster.
To do that, go ahead and create a workflow in your repository by creating a file at .github/workflows/ci.yaml
and add the following YAML to it:
This will run the workflow on any pull request that changes files under the stable charts directory.
The Lint & kubeval charts include:
- Version checking
- YAML schema validation on
Chart.yaml
- YAML linting on
Chart.yaml
andvalues.yaml
- Maintainer validation on changed charts
- Validate the configuration using Kubeval
And Commits to master branch workflow will deal with releasing your charts using GitHub pages.
Remember that gh-pages
the branch you created earlier? Now you can use it to publish your fully tested Helm chart. Create another GitHub workflow, this time at .github/workflows/release.yaml
But first, you need to create a secret for the user that kicked off the workflow. Go to GitHub personal access token, click your profile photo, then click Settings > In the left sidebar, click Developer settings > In the left sidebar, click Personal access tokens > Click Generate new token > Give your token a descriptive name > Select the scopes or permissions, you’d like to grant this token. To use your token to access repositories from the command line, select repo > Click Generate token > Click to copy the token to your clipboard. For security reasons, after you navigate off the page, you will not be able to see the token again.
Create a secret in your repository, CR_TOKEN.
And add the following YAML to it:
It will check out the repository, set the configuration of Git to the user that kicked off the workflow, and run the chart releaser action. The chart releaser action will package the chart, create a release from it, and update the index.yaml
file in the gh-pages
branch.
Once that’s all configured, any time a change under the charts directory is checked in, like from a pull request, your Github workflow will run and your charts will be available almost instantly!
git add stable/kafka/
git commit -m "Added kafka charts"
git push origin kafka
Next, add the repository to Helm so you can use it.
helm repo add helm-charts https://anup1384.github.io/helm-charts/
helm repo update
And finally, install the Kafka chart in the Kubernetes cluster.
helm upgrade --install kafka helm-charts/kafka
I hope this blog was useful to you. Looking forward to claps and suggestions. For any queries, feel free to comment.
Don’t forget to check out my other posts:
- Deploying and Scaling Jenkins on Kubernetes
- Setup ArgoCD in Kubernetes
- how to set up the Elasticsearch cluster on Kubernetes
- Kubernetes application logging using fluentd
Join FAUN: Website 💻|Podcast 🎙️|Twitter 🐦|Facebook 👥|Instagram 📷|Facebook Group 🗣️|Linkedin Group 💬| Slack 📱|Cloud Native News 📰|More.
If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇