Deploying Nginx using a Helm Chart Hosted on GitHub Pages
Helm is a powerful package manager for Kubernetes that allows you to define, package, and distribute applications as Helm charts.
Prerequisites
- A GitHub account
- A Kubernetes cluster (minikube, kind, or a cloud provider cluster)
- Helm
- kubectl installed and configured to access the cluster
- git and GitHub CLI (gh) installed
Steps to package and publish a helm chart
Step 1: Create the Nginx Helm Chart
1
| helm create nginx-chart
|
- This creates a directory structure like:
1
2
3
4
5
6
7
8
9
10
11
| nginx-chart/
├── charts/
├── templates/
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
├── Chart.yaml
├── values.yaml
|
- Modify values.yaml to customize the deployment:
1
2
3
4
5
6
7
8
| replicaCount: 2
image:
repository: nginx
tag: latest
pullPolicy: IfNotPresent
service:
type: LoadBalancer
port: 80
|
Step 2: Package the Helm Chart
1
| helm package nginx-chart
|
- This generates a
.tgz file
, e.g., nginx-chart-0.1.0.tgz
.
Step 3: Create a GitHub Repository for the Helm Chart
1
| gh repo create helm-charts --public --description "Helm charts repository"
|
git init
1
| git remote add origin https://github.com/<your-username>/helm-charts.git
|
- Move the .tgz package into this repository and create an index.yaml file:
1
| helm repo index . --url https://<your-username>.github.io/helm-charts/
|
- Commit and push the changes:
1
2
3
| git add .
git commit -m "Added Nginx Helm chart"
git push origin main
|
Step 4: Publish the Helm Chart to GitHub Pages
- Enable GitHub Pages in your repository:
- Go to Settings → Pages.
- Under “Branch”, select main and / (root).
- Click “Save”.
- Your Helm chart will be available at:
https://<your-username>.github.io/helm-charts/index.yaml
Step 5: Add and Use the Remote Helm Chart
1
| helm repo add myrepo https://<your-username>.github.io/helm-charts/
|
- Install Nginx using the chart:
1
| helm install my-nginx myrepo/nginx-chart --namespace default --create-namespace
|
1
| kubectl get pods,svc,deploy,rs
|
Conclusion
You have successfully created an Nginx Helm chart, packaged it, published it to GitHub Pages, and used it to install Nginx on a Kubernetes cluster. This approach can be used for deploying other applications as well. Happy Helm charting!