This repository contains a comprehensive Infrastructure as Code (IaC) setup using Terraform and Terragrunt to provision a highly available AWS Elastic Kubernetes Service (EKS) cluster, along with its underlying Virtual Private Cloud (VPC) and essential Kubernetes add-ons.
This setup is designed for scalable, production-ready Kubernetes environments, abstracting the complexity of AWS networking and EKS control plane management. By utilizing Terragrunt, the architecture keeps configurations DRY (Don't Repeat Yourself) across multiple environments (e.g., dev and staging).
The automation provisions the following components:
- Dedicated VPC
- Public and private subnets across multiple Availability Zones
- Internet Gateway
- NAT Gateway
- Route tables
- Managed Kubernetes control plane
- Managed node groups
- Support for both:
ON_DEMANDSPOTinstances
- Secure and least-privilege IAM access for Kubernetes workloads
-
AWS VPC CNI
- Native AWS networking for Kubernetes pods
-
Cluster Autoscaler
- Automatically scales worker nodes based on pod resource requests
-
AWS EBS CSI Driver
- Provides lifecycle management for Amazon EBS volumes
-
AWS Load Balancer Controller
- Manages:
- Application Load Balancers (ALB) for Ingress
- Network Load Balancers (NLB) for Services
- Manages:
-
EKS Pod Identity Agent
- Simplifies IAM permission management for applications running on EKS
-
EKS OIDC Provider setup
- It gives permissions to a specific Kubernetes Service Account. Only the pods using that service account get those specific permissions (e.g., access to one specific S3 bucket).
- It's an old way to provide pod access to AWS resources. Modern way to to use EKS Pod Identity. ( I have Disabled it by default )
Ensure the following tools are installed and configured:
| Tool | Version |
|---|---|
| Terraform | >= 1.0 |
| Terragrunt | Latest |
| AWS CLI | v2 |
| kubectl | Matching EKS version (e.g., 1.35) |
| Helm | v3.1.1+ |
Create an S3 bucket for Terraform remote state storage:
- Bucket Name:
dreams-unlimited - Region:
ap-south-1 - Enable versioning
Create an IAM role named:
terraformAttach:
AdministratorAccess
Create a policy named:
AllowTerraformThis policy should allow assuming the terraform IAM role.
Configure your local AWS credentials:
~/.aws/credentialsterragrunt-eks-module/
├── vpc/
├── eks/
└── eks-addons/
terragrunt-eks-live/
├── dev/
└── staging/| Directory | Purpose |
|---|---|
terragrunt-eks-module/ |
Reusable and versioned Terraform modules |
terragrunt-eks-live/ |
Live environment Terragrunt configurations |
dev/ |
Development environment |
staging/ |
Staging environment |
Update the following files in both dev and staging environments:
terragrunt.hclenv.hcl
Configure:
- AWS Account ID
- IAM Role ARN
- AWS profile names
Navigate to your desired environment:
cd terragrunt-eks-live/devInitialize Terragrunt:
terragrunt run-all init -upgradeterragrunt run-all plan[~/terragrunt-eks-live: 10:33:02 ]:terragrunt run-all apply --non-interactive
[~/terragrunt-eks-live: 10:33:04 ]: terragrunt run --all plan --filter '!staging' plan ( If you want to run for dev infraGenerate the kubeconfig file:
aws eks update-kubeconfig \
--region us-east-1 \
--name dev-demo \
--profile amit \
--role-arn arn:aws:iam::<YOUR_ACCOUNT_ID>:role/terraformDeploy the demo applications available in the demo/ folder to validate:
- Cluster Autoscaler
- AWS Load Balancer Controller
- AWS EBS CSI Driver
Destroy the infrastructure:
cd terragrunt-eks-live/dev
terragrunt run-all destroy --non-interactive- Recommended for multi-environment Kubernetes deployments on AWS
- Designed with reusable Terraform modules and Terragrunt orchestration
- Supports production-grade networking and autoscaling patterns
- Uses IRSA and Pod Identity for secure AWS access from workloads