Creating and Hosting Helm Charts for Kubernetes Operators

Featured image



Overview

Learn how to create Helm charts for Kubernetes Operators and host them on GitHub Pages.


🛠 Creating Helm Charts

Installation

# macOS
brew install helm

# Linux
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

Chart Structure

helios-lb [main|✔] 
13:16 $ tree helm
helm/
├── README.md                  # Chart usage guide and parameter documentation
└── helios-lb/                 # Main chart directory
    ├── Chart.yaml            # Chart metadata (version, dependencies, etc.)
    ├── crds/                 # CRD definition files
    │   └── heliosconfig.yaml # HeliosConfig CRD specification
    ├── templates/            # Kubernetes resource templates
    │   ├── NOTES.txt        # Usage notes displayed after installation
    │   ├── _helpers.tpl     # Common template functions
    │   ├── crd-clenaup-hook.yaml    # Helm hook for CRD cleanup
    │   ├── customresource/   # CR templates
    │   ├── deployment.yaml   # Controller deployment
    │   ├── namespace.yaml    # Namespace definition
    │   ├── rbac.yaml        # Permission settings (Role, RoleBinding)
    │   ├── service.yaml     # Service definition
    │   └── serviceaccount.yaml # ServiceAccount definition
    ├── values/              # Values files for different use cases
    │   ├── basic-values.yaml  # Basic configuration
    │   ├── port-values.yaml   # Port-based configuration
    │   └── weight-values.yaml # Weight-based configuration
    └── values.yaml          # Default values file


Packaging and Hosting

You can use Github Pages for web hosting by packaging.

GitHub Pages is a special feature of GitHub, a system that automatically webhosts the gh-pages branch. Here’s how it works.

GitHub Pages Setup

# Create gh-pages branch
git checkout --orphan gh-pages

# Package helm chart
helm package ./helm/helios-lb

# Create index file
helm repo index . --url https://username.github.io/repo/helm-repo

# Commit and push
git add index.yaml helios-lb-*.tgz
git commit -m "Add helm chart repository"
git push origin gh-pages


Automation Process

  1. GitHub detects gh-pages branch
  2. Automatically assign address https://[username].github.io/ [repository-name]
  3. Provides the content of the branch to a static website


Repository Structure

File Purpose
index.yaml Chart metadata and version information
helios-lb-*.tgz Packaged helm chart
README.md Usage documentation


Best Practices

1. Clean Branch:
   - Keep gh-pages branch clean
   - Only include repository files
   - Remove unnecessary files

2. Version Control:
   - Use semantic versioning
   - Update Chart.yaml properly
   - Document changes

3. Documentation:
   - Include clear installation instructions
   - Document all values
   - Provide usage examples

4. Testing:
   - Test chart installation
   - Verify all templates
   - Check dependencies


Usage Example

# Add repository
helm repo add helios-lb https://somaz94.github.io/helios-lb/helm-repo

# Install chart
helm install helios-lb helios-lb/helios-lb

# Verify installation
helm list
kubectl get pods


🚨 Warning

# create helm-repo with main branch
mkdir helm-repo
cd helm-repo
helm package ../helm/helios-lb

# create index.yaml
helm repo index . --url https://somaz94.github.io/helios-lb/helm-repo

cd ../
mv helm-repo ../

# create gh-pages branch
git checkout --orphan gh-pages  # create new branch
git rm -rf .                    # remove all files
mv ../helm-repo .

git add .
git commit -m "Add Helm chart repository"
git push origin gh-pages

Reference