Helm Setup and Configuration Guide
Introduction
Helm is a package manager for Kubernetes that allows you to define, install, and upgrade even the most complex Kubernetes applications. This guide will walk you through setting up and configuring Helm for both development and production environments.
Prerequisites
- Kubernetes cluster (minikube, kind, or a cloud provider)
kubectlconfigured to communicate with your cluster- Basic understanding of Kubernetes concepts
Installation
Installing Helm
bash
# Download and install the Helm binary
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
# Verify the installation
helm versionDevelopment Environment Setup
1. Initialize Helm Repository
bash
# Add the stable Helm repository
helm repo add stable https://charts.helm.sh/stable
# Update the repository
helm repo update2. Create a Test Chart
bash
# Create a new chart
helm create my-app
# Examine the chart structure
ls -la my-app/3. Configure Values for Development
Edit the my-app/values.yaml file to set development-specific configurations:
yaml
# Development-specific values
replicaCount: 1
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 100m
memory: 128Mi4. Install the Chart in Development
bash
# Install with development values
helm install my-app-dev ./my-app --values ./my-app/values.yaml
# Check the deployment
helm list
kubectl get podsProduction Environment Setup
1. Creating Production Values
Create a production-values.yaml file:
yaml
# Production-specific values
replicaCount: 3
resources:
limits:
cpu: 1000m
memory: 1Gi
requests:
cpu: 500m
memory: 512Mi
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-prod2. Setting Up Role-Based Access Control (RBAC)
bash
# Create a service account for Helm
kubectl create serviceaccount helm-user -n kube-system
# Create a ClusterRoleBinding for the service account
kubectl create clusterrolebinding helm-user-cluster-admin \
--clusterrole=cluster-admin \
--serviceaccount=kube-system:helm-user3. Using Helm Secrets for Production
bash
# Install the Helm secrets plugin
helm plugin install https://github.com/jkroepke/helm-secrets
# Encrypt sensitive values
helm secrets enc production-secrets.yaml
# Use secrets in deployment
helm secrets install my-app-prod ./my-app \
--values ./my-app/values.yaml \
--values ./production-values.yaml \
--values ./production-secrets.yaml4. CI/CD Integration
Example GitHub Actions workflow:
yaml
name: Deploy to Production
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Helm
run: |
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- name: Deploy to Production
run: |
helm upgrade --install my-app-prod ./my-app \
--values ./my-app/values.yaml \
--values ./production-values.yaml \
--set image.tag=${GITHUB_SHA::8}Best Practices
Chart Repository Management
bash
# Package your chart
helm package ./my-app
# Create a local chart repository
mkdir -p chart-repo
mv my-app-0.1.0.tgz chart-repo/
helm repo index chart-repo/
# Host the repository (example with GitHub Pages or AWS S3)Version Control Strategy
- Version your charts: Increment the version in
Chart.yamlwith each change. - Use Git tags: Tag releases in your Git repository.
- Keep a changelog: Document changes between versions.
Helm Rollbacks
bash
# List release history
helm history my-app-prod
# Rollback to a previous version
helm rollback my-app-prod 1Monitoring and Troubleshooting
bash
# Get release status
helm status my-app-prod
# Debug a chart
helm template --debug ./my-app
# Test a release
helm test my-app-prodCommon Commands Reference
bash
# Search for charts
helm search repo nginx
# Show chart details
helm show chart stable/mysql
# List installed releases
helm list --all-namespaces
# Uninstall a release
helm uninstall my-app-dev
# Upgrade a release
helm upgrade my-app-prod ./my-app --values ./production-values.yamlConclusion
This guide covered the basics of setting up and configuring Helm for both development and production environments. By following these practices, you can ensure consistent, reliable deployments across different Kubernetes environments.
Additional Resources
- Helm Documentation
- Artifact Hub - Find and publish Helm charts
- Helm GitHub Repository