Creating EKS Cluster using Terraform Modules

In this short lab, I will show you how to create an EKS Cluster properly using Terraform.

Usually, I’d create a `main.tf` file and put all the resources needed to set up your EKS cluster in one place. But this time, I’ll be using Terraform modules instead.

Modules make things a lot easier to manage. For example, if you need to update inbound rules, I just go to `vpc.tf` instead of digging through `main.tf`. It keeps things organized and makes troubleshooting so much simpler. 

PREREQUESITES

  • AWS account access
  • Knowledge of Kubernetes

Step 1: Create the architecture

This structure shows the key components and their roles in deploying the EKS cluster:

EKS Cluster Deployment
├── VPC Module
│ ├── Subnets
│ ├── Route Tables
│ └── Internet Gateway
├── EKS Module
│ ├── Worker Nodes
│ └── Control Plane
├── Security Group Module
│ ├── Ingress Rules
│ └── Egress Rules
├── Variables
│ ├── VPC Configuration
│ ├── EKS Cluster Settings
│ └── Security Group Parameters
├── Versions
│ ├── Terraform Version
│ ├── AWS Provider Version
│ └── Kubernetes Provider Version
└── Outputs
├── VPC ID
├── EKS Cluster Name
└── Security Group IDs

Step 2: Install AWS CLI

  • Follow the below link to Install AWS CLI.
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

Step 3: Install Terraform (on your local machine)

  • Next, Install Terraform using the below link.
https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli

Step 4: Connect Terraform to AWS

  • For Terraform to speak with AWS, you need AWS credentials. Download Access keys

Step 5: Create Terraform modules

These are the 6 files you will create to deploy your eks cluster:

  • Create VPC module
  • Create EKS module
  • Create Security Groupe module
  • Create variables
  • Create version
  • Create output

Find the modules in this repository: https://github.com/djcloudking/terraform-challenges/tree/main/11_Create%20a%20EKS%20Cluster%20using%20Terraform%20Modules

Step 6: Run Terraform

  • Initialize Terraform
    Run terraform init. This step sets up the Terraform environment, downloading necessary modules, providers, and configurations.
  • Review the Terraform Configuration (Optional)
    Use terraform plan to preview the infrastructure changes Terraform will apply. This helps ensure the configuration aligns with your expectations before deployment.
  • Apply the Terraform Configuration
    Execute terraform apply to deploy the EKS cluster along with the VPC. Terraform will handle the creation process seamlessly.

Your EKS cluster has been deployed successfully. And the other resources stated above.

Step 7: Secure EKS cluster

  • Go to EKS console. Click on your cluster.
  • Go to access tab. Copy the access entry. If you don’t have one, click Create Access entry.
  • Navigate back to the compute tab, you should see the node group and the desire state.
  • You have successfully secure your EKS cluster, not everyone should get access to it.

That’s all, folks! Following the steps above will enable you to create EKS cluster using Terraform modules.

Leave a Reply

Your email address will not be published. Required fields are marked *