How to Create an EKS Fargate Cluster with Terraform and Expose Microservices

Listen to this Post

Featured Image

AWS Fargate is a serverless compute engine for containers that works with both Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS). In this guide, we’ll use Terraform to deploy an EKS cluster with Fargate compute and expose a microservice using an AWS Load Balancer.

Prerequisites:

  • AWS CLI configured
  • Terraform installed
  • kubectl installed

Terraform Configuration:

Create a `main.tf` file with the following content:

provider "aws" {
region = "us-west-2"
}

module "eks" {
source = "terraform-aws-modules/eks/aws"
cluster_name = "fargate-cluster"
cluster_version = "1.27"
subnets = ["subnet-123456", "subnet-789012"]
vpc_id = "vpc-123456"

fargate_profiles = {
default = {
name = "fp-default"
selectors = [
{ namespace = "default" }
]
}
}
}

resource "aws_eks_addon" "example" {
cluster_name = module.eks.cluster_id
addon_name = "vpc-cni"
}

output "cluster_endpoint" {
value = module.eks.cluster_endpoint
}

Deploy the Cluster:

Run the following commands:

terraform init 
terraform plan 
terraform apply -auto-approve 

Configure kubectl:

aws eks --region us-west-2 update-kubeconfig --name fargate-cluster 
kubectl get nodes 

Expose a Microservice:

Deploy a sample app:

kubectl create deployment nginx --image=nginx 
kubectl expose deployment nginx --port=80 --type=LoadBalancer 

Verify the Service:

kubectl get svc 

You Should Know:

  • AWS Fargate Pricing: Pay only for vCPU and memory used.
  • Terraform Best Practices: Use remote state (S3 backend).
  • Kubernetes Networking: Ensure VPC CNI addon is installed.
  • Security: Apply IAM roles for least privilege access.

Expected Output:

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 
nginx LoadBalancer 10.100.XX.XXX a1234567890abcdef1234567890abcdef-123456789.us-west-2.elb.amazonaws.com 80:32456/TCP 2m 

What Undercode Say:

AWS Fargate simplifies Kubernetes management by removing node provisioning. Terraform ensures reproducible infrastructure. Always monitor costs and permissions when using serverless EKS.

Prediction:

As serverless Kubernetes adoption grows, expect tighter integration between Fargate, EKS, and DevOps tools like Terraform and GitHub Actions.

URL: Create EKS Fargate Cluster with EKS Add-Ons & Expose Microservices

IT/Security Reporter URL:

Reported By: Darryl Ruggles – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 Telegram