AWS Builder Center
Setting Up a Production-Ready Amazon EKS Cluster with Terraform

Setting Up a Production-Ready Amazon EKS Cluster with Terraform

Kubernetes is the industry standard for container orchestration — but setting it up correctly on AWS is where most people get stuck. Managed node groups, VPC configuration, IAM roles, add-ons — there are a lot of moving parts. Amazon EKS (Elastic Kubernetes Service) handles the control plane for you. But you still need to provision the cluster, configure networking, and install the right add-ons. In this demo, I set up a production-ready EKS cluster using Terraform and a custom add-ons installer script.

Series: AWS-EKS (1 article)

  1. 1
    Setting Up a Production-Ready Amazon EKS Cluster with Terraform This article
Head of DevOps

What We Are Building

AWS Cloud (eu-central-1)
└── VPC (172.16.0.0/16)
├── Public Subnets (eu-central-1a, eu-central-1b)
│ Tags: kubernetes.io/role/elb = 1
├── Private Subnets (eu-central-1a, eu-central-1b)
│ Tags: kubernetes.io/role/internal-elb = 1
└── EKS Cluster: aiops-eks
└── Node Group (t3.medium)
└── Add-ons:
AWS Load Balancer Controller
Metrics Server
Cluster Autoscaler
Node Termination Handler
EBS CSI Driver
External Secrets Operator

Infrastructure as Code with Terraform

The entire cluster was provisioned using a modular Terraform setup. Two modules handle the work — VPC and EKS — keeping the configuration clean and reusable.
terraform. tfvars:
# VPC
vpc_name = "aiops-eks-vpc"
cidr_block = "172.16.0.0/16"
azs = ["eu-central-1a", "eu-central-1b"]
private_subnet_cidrs = ["172.16.48.0/20", "172.16.64.0/20"]
public_subnet_cidrs = ["172.16.0.0/20", "172.16.16.0/20"]
environment = "dev"

# EKS
cluster_name = "aiops-eks"
cluster_version = "1.32"
instance_type = "t3.medium"
desired_capacity = 1
min_capacity = 1
max_capacity = 3
S3 Backend with Native State Locking:
Terraform 1.11 introduced native S3 state locking — no DynamoDB table required:
terraform {
backend "s3" {
bucket = "aiops-terraform-eks-cluster"
key = "eks/terraform.tfstate"
region = "eu-central-1"
encrypt = true
use_lockfile = true # Native S3 locking — no DynamoDB needed
}
}

Key Configuration Decisions

Private subnets for nodes — public subnets for load balancers. Nodes run in private subnets for security. AWS Load Balancer Controller places ALBs in public subnets automatically when the correct subnet tags are present. Nodes never need to be in public subnets.
Subnet tags are mandatory for AWS Load Balancer Controller. Without these tags, the controller cannot determine where to place load balancers:
Public subnets:
kubernetes.io/cluster/aiops-eks = shared
kubernetes.io/role/elb = 1

Private subnets:
kubernetes.io/cluster/aiops-eks = shared
kubernetes.io/role/internal-elb = 1
t3.medium over m3.medium. m3 instances are a 2012-era generation with compatibility issues on modern EKS. t3.medium provides 2 vCPU and 4GB RAM — enough for system pods and workloads in a dev cluster.
Cluster version 1.32 not 1.34. Kubernetes 1.34 did not exist at cluster creation time. Always check the EKS supported versions page before specifying a version in Terraform.

Add-ons Installation

A shell script was used to install all add-ons idempotently — it checks whether each add-on is already running before attempting installation:
./install-addons.sh aiops-eks vpc-00adcebb931f7518b eu-central-1
Add-on: Purpose:
AWS Load Balancer Controller: Provisions ALB/NLB from Kubernetes Service/Ingress
Metrics Server: Provides CPU/Memory metrics for HPA
Cluster Autoscaler: Adds/removes nodes based on pod scheduling demand
Node Termination Handler: Handles EC2 spot interruptions gracefully
EBS CSI Driver: Enables persistent volumes using EBS
External Secrets Operator: Syncs AWS Secrets Manager secrets to K8s secrets

Cluster Verification

After  terraform apply  completed (~15 minutes):
aws eks update-kubeconfig \
--region eu-central-1 \
--name aiops-eks

kubectl get nodes
# NAME STATUS VERSION
# ip-172-16-41-43.eu-central-1.compute.internal Ready v1.34.9-eks

kubectl get pods --all-namespaces
# kube-system aws-node-vjgp4 2/2 Running
# kube-system coredns-6d5765dff7-8mgvc 1/1 Running
# kube-system coredns-6d5765dff7-bzhzp 1/1 Running
# kube-system kube-proxy-sdc56 1/1 Running

Key Lessons

Always check EKS supported Kubernetes versions before specifying one in Terraform. Version 1.34 was specified in the initial config — it does not exist. Always verify on the EKS console or AWS docs before applying.
Use t3 or m5 instance families for EKS nodes — not m3. The m3 family is deprecated and has compatibility issues with modern EKS AMIs. t3.medium is the right choice for dev clusters.
S3 native state locking eliminates the DynamoDB dependency. Terraform 1.11+ supports  use_lockfile = true  in the S3 backend — the lock file is stored as a  .tflock  object in the same S3 bucket. No separate DynamoDB table needed.
Subnet tags must be applied before the Load Balancer Controller is installed. The controller reads these tags at startup to discover subnets. If tags are missing, load balancers fail to provision with a confusing error about subnet discovery.

Full Source Code

All Terraform modules, add-on scripts, and Kubernetes manifests are available on GitHub:


Please feel free to write to @ engr.syedusmanahmad@gmail.com  | LinkedIn  https://www.linkedin.com/in/engrusman-ahmad  for any queries on AWS/DevOps & stay tuned for the next write-up.
If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇

Series: AWS-EKS (1 article)

  1. 1
    Setting Up a Production-Ready Amazon EKS Cluster with Terraform This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article