Helm Lifecycle: From Development to Deployment
Helm is a package manager for Kubernetes that simplifies application deployment, management, and scaling. Understanding the Helm lifecycle ensures efficient chart development, testing, and deployment. This guide covers:
- Creating a Helm Chart
- Implementing Kubernetes Templates
- Writing Automated Tests
- Packaging and Publishing Charts
- Deploying to Kubernetes
- CI/CD Integration
Helm LifeCycle
1. Creating a Helm Chart
1
| curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
|
1
2
| helm create my-app
cd my-app
|
1
2
3
4
5
6
7
8
| my-app/
├── charts/
├── templates/
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── ingress.yaml
├── Chart.yaml
├── values.yaml
|
1
2
3
4
5
6
7
8
| replicaCount: 2
image:
repository: my-app
tag: latest
pullPolicy: IfNotPresent
service:
type: LoadBalancer
port: 80
|
2. Implementing Kubernetes Templates
- Helm templates use Go templating to define Kubernetes manifests dynamically.
- Example
templates/deployment.yaml
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ .Release.Name }}
spec:
containers:
- name: my-app
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
ports:
- containerPort: 80
|
- Render and validate templates:
1
| helm template my-app ./
|
3. Writing Automated Tests
- Helm includes testing via helm test. Add a test in templates/tests/test-connection.yaml:
1
2
3
4
5
6
7
8
9
| apiVersion: v1
kind: Pod
metadata:
name: "{{ .Release.Name }}-test"
spec:
containers:
- name: curl
image: curlimages/curl
command: ['curl', '--fail', 'http://my-app.default.svc.cluster.local']
|
4. Packaging and Publishing Charts
- Create an index file for a Helm repository:
1
2
3
| git add .
git commit -m "Publish Helm chart"
git push origin main
|
- Enable
GitHub Pages
under Settings > Pages
, selecting main
as the source. - Add the repository:
1
2
| helm repo add myrepo https://<your-username>.github.io/helm-charts/
helm repo update
|
5. Deploying to Kubernetes
1
| helm install my-app myrepo/my-app --namespace default --create-namespace
|
1
2
| kubectl get pods
kubectl get svc
|
6. CI/CD Integration
- Use GitHub Actions for automated Helm chart deployment.
- Example
.github/workflows/helm-deploy.yml
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| name: Helm Deploy
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Helm
run: curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- name: Package Helm chart
run: helm package my-app
- name: Publish chart
run: |
helm repo index . --url https://<your-username>.github.io/helm-charts/
git add .
git commit -m "Update Helm chart"
git push origin main
|
Conclusion
By following the Helm lifecycle, you can efficiently create, test, package, publish, and deploy applications to Kubernetes. CI/CD automation ensures consistency and reliability in your deployments.