GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com β€” GitHub - NotHarshhaa/eks-cluster-terraform: This project uses Terraform to provision an Amazon EKS Cluster on AWS. By leveraging Infrastructure as Code (IaC), we automate the deployment of Kubernetes clusters with modular and reusable Terraform configurations.

BranchesTags
Open more actions menu

Latest commit

 

History

6 Commits
6 Commits

Folders and files

NameName
Last commit message
Last commit date
modules
modules
 
 
.gitignore
.gitignore
 
 
.terraform.lock.hcl
.terraform.lock.hcl
 
 
README.md
README.md
 
 
kubernetes.tf
kubernetes.tf
 
 
main.tf
main.tf
 
 
outputs.tf
outputs.tf
 
 
provider.tf
provider.tf
 
 
variables.tf
variables.tf
 
 

Repository files navigation

πŸš€ Deploy an EKS Cluster with Terraform – Like a Boss!

banner


πŸ“Œ Project Overview

EKS Cluster Deployment

This project uses Terraform to provision a complete Amazon EKS environment on AWS with Infrastructure as Code (IaC):

πŸ”Ή A VPC with two public subnets across two Availability Zones, an Internet Gateway and public routing.
πŸ”Ή A managed EKS cluster with a managed node group (IAM roles created automatically, names unique per deployment).
πŸ”Ή A demo workload: a 2-replica nginx Deployment exposed through an AWS Load Balancer via a Kubernetes Service.

πŸ”Ή Kubernetes (K8s) manages containerized applications efficiently.
πŸ”Ή EKS (Elastic Kubernetes Service) is a managed K8s solution on AWS.
πŸ”Ή Terraform simplifies infrastructure provisioning with reusable modules.


πŸ—οΈ Architecture

flowchart LR
    U(["πŸ‘€ User"]) -->|"HTTP :80"| LB["AWS Load Balancer"]

    subgraph VPC["VPC 10.0.0.0/16"]
        subgraph AZ1["Public Subnet 1 (AZ-1)"]
            N1["Worker Node (t3.small)<br/>nginx Deployment Β· 2 replicas"]
        end
        subgraph AZ2["Public Subnet 2 (AZ-2)"]
            N2["Worker Node (scales up to max 2)"]
        end
        CP["EKS Control Plane"]
        IGW["Internet Gateway"]
    end

    LB -->|"node port"| N1
    LB -.-> N2
    U --> IGW
    CP -.->|"manages"| N1
    CP -.->|"manages"| N2
Loading

πŸ“ Project Structure

The repository follows a modular structure for better organization and reusability:

EKS-CLUSTER-TERRAFORM/
│── modules/                   # Terraform modules  
β”‚   β”œβ”€β”€ eks/                   # EKS module  
β”‚   β”‚   β”œβ”€β”€ main.tf            # EKS cluster, managed node group, IAM roles  
β”‚   β”‚   β”œβ”€β”€ variables.tf       # Variables for the EKS module  
β”‚   β”‚   β”œβ”€β”€ outputs.tf         # Outputs for the EKS module  
β”‚   β”œβ”€β”€ vpc/                   # VPC module  
β”‚   β”‚   β”œβ”€β”€ main.tf            # VPC, public subnets, IGW, routing  
β”‚   β”‚   β”œβ”€β”€ variables.tf       # Variables for the VPC module  
β”‚   β”‚   β”œβ”€β”€ outputs.tf         # Outputs for the VPC module  
β”‚  
│── .gitignore                 # Git ignore file  
│── .terraform.lock.hcl        # Provider lock file (generated by `terraform init`, committed)  
│── kubernetes.tf              # Demo nginx Deployment + LoadBalancer Service  
│── main.tf                    # Root configuration: wires the VPC + EKS modules together  
│── outputs.tf                 # Root outputs (cluster info, ready-to-run kubectl command)  
│── provider.tf                # Provider versions + AWS/Kubernetes provider configuration  
│── variables.tf               # Root variables (AWS region)  
│── README.md                  # Documentation (this file)  

πŸ”Ή modules/vpc – Handles VPC and networking setup, tagged for Kubernetes load-balancer discovery.
πŸ”Ή modules/eks – Manages the EKS control plane, managed node group and IAM roles.
πŸ”Ή provider.tf – Provider configuration; the Kubernetes provider authenticates via aws eks get-token.
πŸ”Ή main.tf – Root Terraform script that calls the modules.
πŸ”Ή kubernetes.tf – Deploys the demo application into the cluster.
πŸ”Ή outputs.tf – Displays useful deployment details.


🎯 Why Terraform for EKS?

βœ” Automated & Repeatable Deployments – Reduce human error.
βœ” Infrastructure as Code (IaC) – Easily track changes.
βœ” Dependency Awareness – Ensures resources are created in the correct order.
βœ” Scalability & Reusability – Modular design for better maintainability.


⚑ Prerequisites

Tool Version Why
βœ… Terraform >= 1.3 Provisioning (download)
βœ… AWS CLI v2 latest Credentials and cluster authentication (the Kubernetes provider calls aws eks get-token)
βœ… kubectl matches cluster Interacting with the cluster (install)
βœ… AWS Account β€” With credentials configured via aws configure or environment variables

πŸš€ Deployment Steps

1️⃣ Clone the Repository

git clone https://github.com/NotHarshhaa/eks-cluster-terraform
cd eks-cluster-terraform

2️⃣ Configure the Region (Optional)

The default region is us-east-1. Change it in variables.tf or override it when running Terraform:

terraform plan -var="aws_region=eu-central-1"

3️⃣ Initialize, Plan & Apply Terraform

terraform init      # Initialize Terraform backend + download providers
terraform plan      # Preview infrastructure changes
terraform apply     # Deploy infrastructure (takes ~15 min for EKS)

πŸ“Œ Expected Outputs: EKS cluster name & endpoint, VPC/subnet IDs, and a ready-to-run configure_kubectl command.


4️⃣ Connect to Your EKS Cluster

Configure kubectl using the command Terraform printed, or:

aws eks update-kubeconfig --name <EKS_CLUSTER_NAME> --region <AWS_REGION>

Verify the cluster and demo app:

kubectl get nodes
kubectl get deployment terraform-project102
kubectl get service terraform-project102

Grab the load balancer address and open it in your browser:

kubectl get service terraform-project102 -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'
# β†’ http://<ELB-HOSTNAME>  (may take a few minutes to become available)

βš™οΈ Common Configuration Knobs

Everything is defined in main.tf and documented in the module variables.tf files. The most useful settings:

Setting Where Default
AWS region variables.tf us-east-1
VPC / subnet CIDRs main.tf β†’ module "vpc" 10.0.0.0/16, 2 Γ— /24
Node instance type main.tf β†’ module "eks" t3.small
Node count (desired / min / max) main.tf β†’ module "eks" 1 / 1 / 2
Kubernetes version main.tf β†’ cluster_version latest AWS default
SPOT nodes (cheaper) main.tf β†’ capacity_type ON_DEMAND
Public API access CIDRs main.tf β†’ public_access_cidrs 0.0.0.0/0
SSH access to nodes main.tf β†’ key_pair disabled

πŸ’‘ Enable SSH to nodes by setting key_pair to the name of an existing EC2 key pair. Without a source security group this opens port 22 to 0.0.0.0/0, so prefer setting remote_access_source_security_group_ids too.


πŸ”’ Security Notes

  • The Kubernetes API is publicly reachable from 0.0.0.0/0 for convenience. Restrict public_access_cidrs to your IP for anything beyond a demo.
  • Worker nodes run in public subnets to keep the setup simple. For production, deploy nodes into private subnets with NAT.
  • SSH to nodes is disabled by default.
  • IAM role names are prefixed with the cluster name, so re-deploying this stack into the same account never collides.

🧹 Destroy the Infrastructure

⚠️ Cost warning: a running EKS cluster ($0.10/h), the EC2 nodes and the load balancer all cost money β€” destroy when you're done ($80+/month if left running).

terraform destroy

Alternatively, if using Terraform Cloud, go to: Settings β†’ Destruction & Deletion β†’ Queue destroy plan.


πŸ”§ Troubleshooting

Symptom Likely cause / fix
aws eks get-token errors during plan/apply AWS CLI v1 is too old β€” install/update to AWS CLI v2
Service EXTERNAL-IP stays <pending> Load balancer subnet discovery failed β€” this repo tags public subnets with kubernetes.io/role/elb; check kubectl describe service terraform-project102
terraform apply fails on key_pair The named EC2 key pair doesn't exist in the region β€” create it or leave key_pair unset
Node group fails to launch (e.g. in us-east-1e) Instance type unavailable in the chosen AZ β€” retry, or use a different instance_types value
scaling_desired_size validation error Desired size must be between scaling_min_size and scaling_max_size

☁️ Terraform Cloud Integration (Optional)

1️⃣ Go to Terraform Cloud
2️⃣ Create a new Workspace and connect your GitHub repository.
3️⃣ Add the following environment variables:

AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION
CONFIRM_DESTROY

ℹ️ The Kubernetes provider shell-outs to aws eks get-token, so the Terraform Cloud workers also need the AWS CLI v2 installed (available on recent worker images).


πŸŽ‰ Congratulations! You've Successfully Deployed an EKS Cluster with Terraform!

Success


⭐ Hit the Star!

If you find this repository helpful and plan to use it for learning, please consider giving it a star ⭐. Your support motivates me to keep improving and adding more valuable content! πŸš€


πŸ› οΈ Author & Community

This project is crafted with passion by Harshhaa πŸ’‘.

I’d love to hear your feedback! Feel free to open an issue, suggest improvements, or just drop by for a discussion. Let’s build a strong DevOps community together!


πŸ“§ Let's Connect!

Stay connected and explore more DevOps content with me:

LinkedIn GitHub Telegram Dev.to Hashnode


πŸ“’ Stay Updated!

Want to stay up to date with the latest DevOps trends, best practices, and project updates? Follow me on my blogs and social channels!

Follow Me

About

This project uses Terraform to provision an Amazon EKS Cluster on AWS. By leveraging Infrastructure as Code (IaC), we automate the deployment of Kubernetes clusters with modular and reusable Terraform configurations.

Topics

awsaws-eksdeploymenteksterraformterraform-modules

Resources

Readme
Activity

Stars

74 stars

Watchers

2 watching

Forks

68 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 β€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800Γ—600. No cookies required.