Kubernetes

Helm

Tutorial

Automate Kubernetes Helm Chart Release with Github Pages

Vatsal Bajpai
Vatsal Bajpai
8 min read·
Cover Image for Automate Kubernetes Helm Chart Release with Github Pages

In this blog, we'll dive into how to automate the release of Helm charts and deploy them to GitHub Pages using GitHub Actions. We'll walk through the entire process, from setting up the workflow to hosting the generated Helm chart documentation on GitHub Pages. This is a powerful approach for maintaining and distributing Helm charts in a fully automated, CI/CD pipeline.

Workflow Overview

The process of automating the release of Helm charts involves two main steps:

  1. Helm Chart Release Automation: Using GitHub Actions to automate the creation and release of Helm charts.
  2. Hosting on GitHub Pages: Deploying the generated Helm chart documentation on GitHub Pages for easy distribution and access.

We’ll use GitHub Actions to achieve both steps. This allows us to automate the Helm chart release process whenever changes are made to the charts.

Prerequisites

Before we start automating, ensure you have the following in place:

  1. A GitHub repository where your Helm charts are stored.
  2. A charts/ directory containing your Helm chart(s).
  3. GitHub Pages enabled for your repository.

Step 1: Create GitHub Actions Workflow

We'll start by creating a GitHub Actions workflow to automate the Helm chart release and deployment. This workflow will be triggered when changes are made to the Helm charts in the repository.

Here is an example of a GitHub Actions workflow YAML configuration:

name: Release Helm Chart & Deploy to GitHub Pages

on:
  push:
    branches:
      - main
    paths:
      - 'charts/**'  # Trigger on changes to charts directory

jobs:
  releaseHelmChart:
    needs: buildAndDeploy  # Optional: If you have other jobs before this, like building Docker images
    runs-on: ubuntu-latest

    permissions:
      pages: write  # Required to deploy to GitHub Pages
      contents: write  # Allows the job to push to the repository

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0  # Ensures the full git history is fetched

      - 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@v4  # Installs Helm CLI

      - name: Run chart-releaser
        uses: helm/chart-releaser-action@v1.6.0
        with:
          charts_dir: charts  # The directory containing your Helm charts
        env:
          CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"  # GitHub Token for authentication

Explanation of the Workflow:

  1. on: push: This trigger ensures that the workflow runs when changes are pushed to the main branch and affect the charts/ directory.

  2. releaseHelmChart Job

    • runs-on: ubuntu-latest: Runs on the latest Ubuntu environment.
    • Permissions: The pages: write permission is needed to publish to GitHub Pages, and contents: write is required to push changes to the repository.
    • Steps:
      • Checkout the repository: This ensures that the latest code is fetched from the repository.
      • Configure Git: Sets the Git username and email to match the GitHub actor. This is essential for making commits in the workflow.
      • Install Helm: Uses the azure/setup-helm action to install Helm.
  3. Run Chart Releaser: The helm/chart-releaser-action@v1.6.0 action is used to release Helm charts and upload them to the GitHub Pages branch. It packages the charts found in the charts directory and pushes them to the gh-pages branch of the repository.

Chart Releaser Action: The action helm/chart-releaser-action helps automate the release of Helm charts to GitHub Pages. It will package the charts and create a new release, which will then be hosted on GitHub Pages.

GitHub Token: The CR_TOKEN environment variable is set to ${{ secrets.GITHUB_TOKEN }} to authenticate the push to the gh-pages branch. This token is automatically provided by GitHub and is used to authenticate the GitHub Actions workflow.

Step 2: Create and Configure the gh-pages Branch

Once the Helm charts are packaged and released, you need to create the gh-pages branch to serve as the source for GitHub Pages.

  1. Create the gh-pages Branch
  • Navigate to your GitHub repository.
  • Open the "Branches" tab.
  • Click the "New branch" button and create a branch named gh-pages.
  1. Set the gh-pages branch as the source for GitHub Pages:
  • Go to the repository settings.
  • Scroll down to the "GitHub Pages" section.
  • In the "Source" dropdown, select the gh-pages branch and choose / (root) as the folder to serve from.

Now, whenever the workflow runs successfully, it will automatically update the Helm chart documentation and deploy it to the gh-pages branch, making it accessible at a URL like:

https://<your-github-username>.github.io/<repository-name>

Directory Structure After Helm Chart Release

After the Helm charts are released and deployed to GitHub Pages, the structure of the gh-pages branch will look something like this:

gh-pages/
  ├── index.yaml

# The index.html file is generated as part of the Helm chart release process and serves as the landing page for your Helm chart documentation.

Step 3: Installing the Helm Chart

  1. Add the Helm repository to your Helm client:
helm repo add my-repo https://<your-github-username>.github.io/<repository-name>
  1. Update your Helm repositories:
helm repo update
  1. Install the Helm chart:
helm install my-chart my-repo/<chart-name>

Conclusion

Automating Helm chart releases and hosting them on GitHub Pages streamlines the process of maintaining and distributing Kubernetes applications. By setting up a GitHub Actions workflow, you can ensure that every change to your Helm charts automatically triggers a release and publishes it to GitHub Pages, making the charts easily accessible to others.

This method also ensures that the charts are versioned, and the process is fully automated, reducing human error and allowing teams to focus on other important aspects of development.

I hope this blog post provides valuable insights into DevOps, Kubernetes and cost-saving benefits. If you have any questions or need further assistance, feel free to ask!

If you like this, follow us on Twitter and LinkedIn and explore our platform to help save you more cloud costs - gravitycloud.ai


footer

Share this Article: