This repository contains Terraform code to provision an Amazon Elastic Kubernetes Service (EKS) cluster on AWS. The IaC script includes configuration for the VPC, security groups, IAM roles, and more.
Before using this Terraform script, make sure you have the following prerequisites:
- Terraform installed on your local machine.
kubectl
for managing your Kubernetes cluster.- AWS CLI configured with the necessary credentials.
- A basic understanding of Terraform and AWS services.
- Estimated EC2 Monthly cost: 12,406.54 USD
- Estimated EC2 10 Days cost: 4,135.51 USD
- Total vCPU and Memory: 296 vCPU 592 GB
- Total Disk: 18.94 TB
-
Clone this repository to your local machine:
git clone https://github.com/iwillbeacloudguru/terraform-eks.git cd terraform-eks
-
Create a terraform.tfvars file based on your requirements. Here's an example:
### terraform.tfvars ### aws_region = "ap-southeast-1" project_name = "eks-dev" cluster_version = "1.28" # Comment this if you don't use named profile in aws configure profile = "AdministratorAccess-xxxxx" # Adjust Sizing in this section node_size = "t3.large" node_number = 3 disk_size = 32 ami_type = "AL2_x86_64" node_type = "ON_DEMAND"
-
Initialize Terraform:
terraform init
-
Review the plan:
terraform plan -out tfout
-
Apply the configuration:
terraform apply "tfout"
-
After provisioning is complete, you can access your EKS cluster and manage it using kubectl and Helm. Make sure to configure your kubectl and Helm with the provided credentials in your Terraform configuration.
aws eks update-kubeconfig --name <cluster-name> or aws eks update-kubeconfig --name <cluster-name> --profile <aws configure profile>
-
Try to use the Kubernetes API to get information about your workload. You can beautify the results with kubectl:
kubectl get all -A -o wide
-
Change to the ./test directory.
-
Run the following command to deploy a namespace, deployment, service, and ingress:
sh echoserver.sh
-
Run an AWS CLI command to get the ALB DNS. Replace and with the appropriate values:
aws eks describe-cluster --name <cluster-name> --query "cluster.resourcesVpcConfig.clusterSecurityGroup" --output text aws ec2 describe-security-groups --group-ids <security-group-id> --query "SecurityGroups[0].GroupName" --output text aws elbv2 describe-load-balancers --name <alb-name> --query "LoadBalancers[0].DNSName" --output text
Remember to replace with the actual name of your EKS cluster, with the security group associated with your EKS cluster, and with the name of your ALB. These AWS CLI commands will help you obtain the ALB DNS to access your application.
-
After obtaining the ALB DNS, use the following curl command to access your deployed workload. Replace and with the actual values:
curl http://<alb-dns>/<path>
Where: alb-dns is the DNS name of your Application Load Balancer. path is the path to your deployed application.
-
Delete the namespace, deployment, service, and ingress in the cluster:
sh echoserver-terminate.sh
-
To destroy the resources provisioned by Terraform, run:
terraform destroy --auto-approve
Porames Jariyayanyong | Technical Architect, AWS @ NTT DATA Inc.