Hosting Your Own Helm Chart on GitHub with Chart Releaser

Our favorite time to solve devops issue with opensource solution have come again, yay~

Hosting Your Own Helm Chart on GitHub with Chart Releaser

Our favorite time to solve devops issue with opensource solution have come again, yay~

MoBagel’s 8ndpoint is a platform with multiple micro services to help store owners make better decision about restock, ad performance, customer segments, and repurchase recommendations. Though the platform consists of multiple services, they share very similar deployment technology. For example, we always use Fastapi for backend, and our frontend app is served very similarly, and database technologies are very similar as well.

Helm is a great tool for managing Kubernetes deployment, says their official website:

Helm is the best way to find, share, and use software built for Kubernetes

Helms takes care of the following issues when managing a Kubernetes application:

  1. yaml file template language and generation.
  2. separating deployment spec (under templates) and configuration (values.yaml).
  3. version control: chart’s version control and deployment version control.
  4. deployment operation: install, uninstall, upgrade, rollback, status check, …etc.

With Helm and the various services that we need to manage, a way to manage and collaborate on Helm chart is necessary. Let me briefly talk about our Helm Chart structure, and then shares about how we build our public and open sourced helm chart repository.

How MoBagel Structure Helm Charts

As we mentioned, a lot of our micro services share common deployment structure, just different parameters. So we create a public Helm chart repository for MoBagel, and host all common charts on this repository.

Developers can use common charts by adding our repository to helmhelm repo add mobagel https://mobagel.github.io/charts

Since these are generic charts, all information are non-sensitive, we can open source this project. As for our deployment, we will be version controlling all deployment parameters, so we need to use private git repository.

To know more about how to create a helm chart, refer to the well written official document. Here we briefly mention how we use the released public chart in our private deployment charts:

  1. In Chart.yaml add public chart as a dependency.
  2. Before chart is deployed, run helm dependency build. The parent chart will be installed as a sub chart under the charts folder.
  3. Since dependencies become sub charts, we simply overwrite chart values in values.yaml file, but with a added nesting level.# in Chart.yaml
    dependencies:
    - name: fastapi
     version: "0.1.0"
     repository: "https://mobagel.github.io/charts"# In values.yaml
    fastapi:
     ingress:
       enabled: true
       hosts:
         - host: some-custom-host.com
           paths:
             - path: /api
               pathType: Prefix
    ... (put the value override for value.yaml for fastapi chart)

Create Chart Repository Hosting on Github

After understanding how chart dependencies are set up, we still need to create our own repository hosting. The official document introduces several ways of doing so, and I find hosting it on GitHub to be the most convenient.

  1. create a repository under your organization, you may name it charts or helm-charts , since this repository will be hosting all your public, shareable charts.
  2. Give it a README.md, and create 2 branch: main and gh-pages
  3. Go to repository’s Setting > Pages, enable Github Pages and set Source to Deploy from a branch, then set branch to gh-pages .
  4. On branch main , create a charts folder, and put your existing helm charts in this folder.
  5. On branch main , add a .github/workflows/release.yml file, this file uses chart releaser action to create chart index file and serve it on your github pages.# release.yml
    name: Release Chartson:
     push:
       branches:
         - mainjobs:
     release:
       runs-on: ubuntu-latest
       steps:
         - name: Checkout
           uses: actions/checkout@v2
           with:
             fetch-depth: 0- name: Configure Git
           run: |
             git config user.name "$GITHUB_ACTOR"
             git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
         - name: Install Helm
           uses: azure/setup-helm@v1
           with:
             version: v3.8.1- name: Run chart-releaser
           uses: helm/chart-releaser-action@v1.4.0
           env:
             CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

In the last step, the chart releaser will perform the following steps automatically for you:

  1. check and compare all charts under charts folder to see if there areany changes.
  2. build the charts and release them as GitHub releases (upload chart as artifact) for you.
  3. update index.yaml file and serve it on gh-branch page.

After all is setup, people can start adding your chart repository byhelm repo add [org-name] [git page url]

A full and working example is given here: https://github.com/MoBagel/charts

And the chart repository can be added ashelm repo add mobagel https://mobagel.github.io/charts

Enjoy having your own helm charts in a few steps, God bless!

A joyful heart is good medicine, but a broken spirit dries up the bones.
Proverbs 17:22