How to deploy Helm charts to Kubernetes from CI
Package an app as a Helm chart and deploy it to Kubernetes from CI with per-environment values and helm upgrade --install, including rollback.
What and why
Helm packages Kubernetes manifests into versioned, parameterized charts. Instead of hand-editing YAML per environment, you template it once and supply values. This tutorial deploys a chart to Kubernetes from CI with per-environment overrides.
Prerequisites
- A Kubernetes cluster and credentials.
- Helm installed.
- A containerized app and a CI pipeline.
Steps
1. Create a chart
helm create web
This scaffolds a chart with templates, a values.yaml, and metadata.
2. Parameterize templates with values
Reference values in templates so they vary by environment:
image:
repository: ghcr.io/acme/web
tag: "{{ .Values.image.tag }}"
replicaCount: {{ .Values.replicaCount }}
Defaults live in values.yaml.
3. Add per-environment value files
Create values-staging.yaml and values-prod.yaml with only the differences, such as replica counts and resource limits. Keep shared defaults in the base file.
4. Authenticate CI to the cluster
Provide a kubeconfig or cloud credentials as CI secrets, scoped to the target namespace. The pipeline needs permission to manage releases in that namespace only.
5. Run helm upgrade in CI
- run: |
helm upgrade --install web ./web \
-f values-prod.yaml \
--set image.tag=${{ github.sha }} \
--namespace web --wait
upgrade --install creates the release if absent and upgrades it otherwise; --wait blocks until resources are ready.
Verification
Run helm status web -n web and confirm the release is deployed. Check kubectl get pods -n web shows the new image tag. Roll back with helm rollback web to confirm release history is tracked.
Next Steps
Lint and template-test charts in CI before deploy. Publish charts to a chart repository for reuse. Combine with a GitOps controller so Helm releases are reconciled from Git.
Prerequisites
- A Kubernetes cluster
- Helm installed
- A containerized app and CI pipeline
Steps
- 1Create a chart
- 2Parameterize templates with values
- 3Add per-environment value files
- 4Authenticate CI to the cluster
- 5Run helm upgrade in CI
- 6Verify the release