Listen to this Post

Using Terraform for Infrastructure as Code (IaC) simplifies the management of AWS Elastic Kubernetes Service (EKS) clusters. This approach ensures resources are reproducible and easy to clean up. Below is a detailed guide with verified commands and configurations.
You Should Know:
1. Terraform Setup for EKS Cluster
Ensure you have Terraform and AWS CLI configured:
aws configure terraform init
2. VPC and EKS Cluster Configuration
Use this Terraform snippet to define a VPC and EKS cluster:
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "eks-vpc"
cidr = "10.0.0.0/16"
azs = ["us-east-1a", "us-east-1b"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
enable_nat_gateway = true
}
module "eks" {
source = "terraform-aws-modules/eks/aws"
cluster_name = "my-eks-cluster"
subnets = module.vpc.private_subnets
vpc_id = module.vpc.vpc_id
}
3. Deploying Apache Web Server on EKS
After cluster creation, deploy Apache using `kubectl`:
kubectl create deployment apache --image=httpd:latest kubectl expose deployment apache --port=80 --type=LoadBalancer
4. Secure Access with RBAC
Define Kubernetes RBAC roles:
apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: default name: apache-role rules: - apiGroups: [""] resources: ["pods"] verbs: ["get", "list"]
5. Monitoring and Scaling
Enable observability with Prometheus and auto-scaling:
kubectl apply -f https://github.com/prometheus-operator/prometheus-operator/releases/download/v0.50.0/bundle.yaml kubectl autoscale deployment apache --cpu-percent=50 --min=1 --max=10
What Undercode Say:
Terraform streamlines EKS cluster deployment, while Kubernetes ensures scalable and secure Apache web server hosting. Key takeaways:
– Use Terraform modules for reusable infrastructure.
– Secure EKS with RBAC and network policies.
– Monitor with Prometheus and scale dynamically.
Expected Output:
AWS EKS Cluster: Ready Apache Deployment: Running on Port 80 RBAC Policies: Applied Auto-scaling: Enabled
Prediction:
Increased adoption of Terraform for multi-cloud Kubernetes deployments, with enhanced security and automation.
URL: Apache Web-Server Deployment on Terraform Deployed EKS Cluster
References:
Reported By: Darryl Ruggles – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅


