Set Up EKS Cluster Using Terraform
Set Up EKS Cluster Using Terraform
Terraform
Introduction:
Amazon Elastic Kubernetes Service (EKS) is a managed Kubernetes service
that makes it easy to run Kubernetes on AWS without needing to install and
operate your own Kubernetes control plane. Terraform is an Infrastructure as
Code (IaC) tool that allows you to define and provision infrastructure using a
high-level configuration language. In this blog, I will show you the steps how to
set up an EKS cluster using Terraform.
Why EKS and Terraform?
EKS abstracts Kubernetes complexities, offering AWS-managed clusters.
Terraform complements EKS by enabling the configuration of AWS resources,
networking, security, and Kubernetes settings using a unified, declarative
approach.
Prerequisites
Before we start, ensure you have the following:
1. AWS Account: You need an AWS account to create EKS and other resources.
2. AWS CLI: Installed and configured with proper permissions.
3. Terraform: Installed on your local machine.
4. kubectl: Installed to interact with your EKS cluster.
In order to create an EKS cluster using terraform we don’t need to write code
from scratch, we can get the module from the terraform registry itself.
[ ]# mkdir eks-terraform
[ ]# cd eks-terraform
Step 2: Second, we need to clone the code from the github repo. To
clone it locally use the below command using any CLI
• Once the bucket has been created then in the cloned repository, locate the
terraform.tf file. Open this file and replace the bucket name with your
actual S3 bucket name. This bucket is used by Terraform to store the state
file.
Step 4: Initialize Terraform
Initialize the Terraform working directory by running:
- Cluster
- VPC
- EC2
- S3
• In order to generate the kube config file in the cluster we can use the
below command;
Commands:
- Once the kubectl is installed now you can run the Kubernetes commands .
That’s it! 😍We have successfully created an EKS cluster using terraform.
Note: Amazon EKS is a managed service. EKS service does not come under free
tier; it is chargeable so make sure to delete the cluster once this project has been
completed.
Clean Up:
If you no longer need the EKS cluster and want to delete all the resources
created by Terraform, you can use the terraform destroy command. This will
remove all the infrastructure that was created: