In this post, we’ll create fully automated build pipeline to host a repository for Helm charts using GitHub Pages and GitHub Actions.
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.
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.
Create a Github Repository
Before proceeding, create a new repository in github. I will name mine helm-charts
but be free to name yours as you want. Head over to github create new repository and fill in the new repository form.
To work on it locally, clone it.
|
|
Create a helm chart
Before proceeding, ensure you have helm
installed. Checkout the helm install page for your OS installation instructions.
I’m going to use a directory ./charts/
for the sources of our charts. I’m creating the default chart for testing purposes, you might want to copy into ./charts/
your existing charts instead.
|
|
In my case, I am creating a chart named app
. You should see output similar to this:
|
|
Push to git repository on GitHub
|
|
Setup GitHub Pages
Next, we need to create a new branch named gh-pages
so as to publish helm charts.
First you need to go ahead and create a gh-pages branch in your repository. As I’m writing this there’s an issue open to do this automatically, but to do it manually you can run the following:
|
|
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
branch you just created.
GitHub Actions
We need a Github actions workflow to create the release for every change we do the repo.
Create a GitHub Actions Workflow .github/workflows/release.yml
in the main branch and add the following configurations as shown below. You can find more details here. This will now turn our repo to self-hosted Helm Chart repo. With every push to the main
branch it will check the chart and if there is a new chart version creates a corresponding GitHub release, adds Helm chart artefacts to the release and creates the index.yaml
on first push or updates the same afterwards with metadata about those releases, which will be then hosted on GitHub Pages.
|
|
When you push some changes to the chart in main
branch, you will notice that an index.yml
gets automatically created. Navigate to Github actions tab to see the workflow triggers.
You can see now in the releases section a new release has been created at the bottom right for app
and index.yaml
would also be updated in gh-pages
branch.
Linting action
As a bonus, we can create another action to lint the charts when there is a pull request on our repo.
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 and values.yaml
- Maintainer validation on changed charts
- Validate the configuration using Kubeval
And Commits to main branch workflow will deal with releasing your charts using GitHub pages.
Using helm chart
Now that our helm chart is created we can use it in our kubernetes cluster for deployment.
|
|
Now you would be able to search your repo and use it in any kubernetes deployment.
|
|
To install the app
chart in the Kubernetes cluster.
|
|
Conclusion
In this blog we have seen how we can use github pages, action and github repo for hosting our helm charts repo.