
Here’s a Terraform module to deploy an AWS Graviton-based Kubernetes (EKS) cluster using ARM64 instances. This setup includes:
✅ Graviton EKS Cluster (M7g, C7g, or R7g instances)
✅ Node Group with ARM64 Instances
✅ Auto Scaling Enabled
✅ IAM Roles & Security Groups
🔹 Step 1: Install Terraform & AWS CLI (If Not Installed)
# Install Terraform
wget https://releases.hashicorp.com/terraform/1.5.5/terraform_1.5.5_linux_amd64.zip
unzip terraform_1.5.5_linux_amd64.zip
sudo mv terraform /usr/local/bin/
terraform -v
# Install AWS CLI
sudo apt update && sudo apt install awscli -y
aws configure # Enter your AWS credentials
🔹 Step 2: Create Terraform Configuration File
Create a new file graviton-eks.tf
and paste the following code:
provider "aws" {
region = "us-east-1" # Change this as needed
}
resource "aws_eks_cluster" "graviton_eks" {
name = "graviton-eks-cluster"
role_arn = aws_iam_role.eks_cluster_role.arn
vpc_config {
subnet_ids = aws_subnet.graviton_subnet[*].id
}
depends_on = [aws_iam_role_policy_attachment.eks_cluster_policy]
}
resource "aws_iam_role" "eks_cluster_role" {
name = "eks-cluster-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = {
Service = "eks.amazonaws.com"
}
Action = "sts:AssumeRole"
}]
})
}
resource "aws_iam_role_policy_attachment" "eks_cluster_policy" {
role = aws_iam_role.eks_cluster_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
}
resource "aws_eks_node_group" "graviton_node_group" {
cluster_name = aws_eks_cluster.graviton_eks.name
node_group_name = "graviton-nodes"
node_role_arn = aws_iam_role.eks_node_role.arn
subnet_ids = aws_subnet.graviton_subnet[*].id
instance_types = ["m7g.medium"] # Change to c7g.large, r7g.xlarge as needed
scaling_config {
min_size = 1
max_size = 3
desired_size = 2
}
ami_type = "AL2_ARM_64"
depends_on = [aws_iam_role_policy_attachment.eks_worker_node_policy]
}
resource "aws_iam_role" "eks_node_role" {
name = "eks-node-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
Action = "sts:AssumeRole"
}]
})
}
resource "aws_iam_role_policy_attachment" "eks_worker_node_policy" {
role = aws_iam_role.eks_node_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
}
resource "aws_vpc" "graviton_vpc" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "graviton_subnet" {
count = 2
vpc_id = aws_vpc.graviton_vpc.id
cidr_block = "10.0.${count.index + 1}.0/24"
availability_zone = element(["us-east-1a", "us-east-1b"], count.index)
map_public_ip_on_launch = true
}
🔹 Step 3: Deploy the Graviton-Based EKS Cluster
Run the following Terraform commands:
terraform init
terraform apply -auto-approve
🔹 Step 4: Configure kubectl
to Access the Cluster
Once the cluster is created, configure kubectl to connect to the EKS cluster:
aws eks --region us-east-1 update-kubeconfig --name graviton-eks-cluster
kubectl get nodes
🔹 Step 5: Deploy a Sample ARM64-Based Kubernetes App
Create a deployment file nginx-arm64.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-arm64
spec:
replicas: 2
selector:
matchLabels:
app: nginx-arm64
template:
metadata:
labels:
app: nginx-arm64
spec:
containers:
- name: nginx
image: public.ecr.aws/nginx/nginx:latest
ports:
- containerPort: 80
Apply the deployment:
kubectl apply -f nginx-arm64.yaml
kubectl get pods -o wide
✅ Conclusion
- 🚀 This Terraform script automates AWS EKS cluster setup with ARM64 (Graviton) instances
- 🏗 Graviton-based Kubernetes clusters reduce costs and improve performance
- 🐳 Multi-arch container images can run efficiently on these instances
- 🔄 Can be extended to deploy workloads like AI/ML, analytics, and web apps
Would you like an auto-scaling and load-balanced Kubernetes setup for production? 🚀