Day 10: Managing Kubernetes with Helm and Terraform
Welcome to Day 10 of the Zero to Platform Engineer in 30 Days challenge! 🚀 Today, we’ll explore how to combine Helm and Terraform, two powerful tools, to simplify the deployment and management of Kubernetes applications.
By the end of this session, you’ll understand:
- The basics of Helm and how it works.
- How Terraform can manage Helm Charts programmatically.
- Practical steps to deploy and manage applications with Helm and Terraform.
What Is Helm?
Helm is a package manager for Kubernetes that helps you deploy applications using pre-configured templates called Charts.
Why Use Helm?
- Simplifies Complex Deployments: Use community-maintained Charts for tools like NGINX, Prometheus, and ArgoCD.
- Standardization: Share Charts across teams for consistent deployments.
- Flexibility: Customize configurations with values files.
- Rollbacks: Easily revert changes to a previous state.
What Is Terraform’s Role?
Terraform’s Helm Provider enables you to:
- Deploy Helm Charts programmatically alongside your infrastructure.
- Automate application updates.
- Track deployments in Terraform state files for consistency.
Hands-On: Using Helm and Terraform Together
Step 1: Install the Helm CLI
- Install the Helm CLI on your machine, following the official installation guide.
- Verify the installation:
helm version
Step 2: Set Up the Terraform Helm Provider
- Add the Helm provider to your Terraform configuration:
provider "helm" {
kubernetes {
config_path = "~/.kube/config"
}
}
- Initialize Terraform:
terraform init
Step 3: Deploy a Helm Chart Using Terraform
- Create a Terraform configuration file:
resource "helm_release" "nginx" {
name = "nginx"
namespace = "default"
chart = "nginx"
repository = "https://charts.bitnami.com/bitnami"
version = "15.4.0"
values = [
<<-EOF
service:
type: NodePort
nodePort: 30001
EOF
]
}
- Apply the configuration:
terraform apply
- Verify the deployment:
kubectl get all -n default
Step 4: Customize Your Helm Deployment
Modify the values section in Terraform to add custom settings, such as replica counts:
values = [
<<-EOF
replicaCount: 3
service:
type: NodePort
nodePort: 30002
EOF
]
Apply the changes:
terraform apply
Verify the changes:
kubectl get all -n default
🎯 Pro tip: Use the -auto-approve flag to skip the confirmation prompt.
Step 5: Rollback to a Previous State
- Update the values section in Terraform to rollback to the previous state:
version = "15.5.0"
- Apply the changes:
terraform state rm helm_release.nginx
helm rollback nginx 1
Activity for Today
- Deploy an NGINX Helm Chart using Terraform.
- Customize the Chart with parameters like replica counts, ports, or environment variables.
- Experiment with upgrades and rollbacks.
What’s Next?
Tomorrow, we’ll explore GitOps with ArgoCD, diving into how you can manage Kubernetes clusters declaratively using Git as the source of truth.
👉 Check it out here: Zero to Platform Engineer Repository
Feel free to clone the repo, experiment with the code, and even contribute if you’d like! 🚀
Follow the Series!
🎉 Don’t miss a single step in your journey to becoming a Platform Engineer! 🎉
This post is just the beginning. Here’s what we’ve covered so far and what’s coming up next:
-
Day 2: Day 2: Containers and Docker - The Building Blocks of Cloud Native
-
Day 3: Containers and Kubernetes - The Building Blocks of Cloud Native
-
Day 4: Deployments and Scaling in Kubernetes - Let’s Get Practical
-
Day 6: ConfigMaps and Secrets – Managing Configurations in Kubernetes
👉 Bookmark this blog and check back every day for new posts in the series. 📣 Share your progress on social media with the hashtag #ZeroToPlatformEngineer to connect with other readers!