How to Setup EKS Cluster using Terraform

Posted By : Baldev Pal | 20-Jun-2022

Step1.Install the terraform on your local machine in ubuntu.

            i. Install the unzip command.

               $ sudo apt-get install unzip

            ii. Download the latest version of terraform.

               $ wget https://releases.hashicorp.com/terraform/1.0.7/terraform_1.0.7_linux_amd64.zip

              iii. Extract the terraform file.

                  $ unzip terraform_1.0.7_linux_amd64.zip         

            iv. After the extract file Move the terraform file to this location /usr/local/bin.

                $ sudo mv terraform /usr/local/bin/

            v. check the terraform version.

                $ terraform -v

 

Step2. Install the Pycharm or VS code to write terraform script.

Step3. Configure the AWS access and secret key in your local machines.

 

Step4. Start writing the terraform script for the EKS cluster setup.

            i. Create a provider.tf file and configure the provider.tf file.

               provider.tf     

            ii. Create a vpc.tf file and configure the VPC.      

                vpc.tf

            iii. Create a subnet.tf file and configure the subnet.

                 subnet.tf

            iv. Create an internet_gatway file and configure the internet_gatway.

                internet_gateway.tf

            v. Create a route_table file and configure the route_tabe.

                routing_tables.tf

            vi. Create a route-table-association.tf file and configure the route-table-association.

                route-table-association.tf

   

            vii. Create a nat_gateway.tf file and configure the nat_gateway.

                 nat_gateway.tf

 

            viii. Create a eips.tf file and configure the Elastic ip.

                   eips.tf

 

            ix. Create a eks.tf file and configure the EKS cluster.

                 eks.tf

            x. Create an esk-node-groups.tf and configure the node group.

                eks-node-groups.tf

 

Step5.After creating the terraform script run the terraform init command.

           $ terraform init

 

Step6.After running terraforms init command run the terraform apply command.

          $ terraform apply

 

 

Step6. After Completing all resources, go to the aws account and check all resources. 

Step7. Install kubectl in your VM or system, and Enable kubectl to communicate with your cluster by adding a new context to the kubectl config file in this command.

      $ aws eks update-kubeconfig  --profile profile_name --region region-code --name cluster-name

 

Step8 After connecting EKS cluster in your VM or system, check the worker node in this command.

$ kubectl get node

 

About Author

Author Image
Baldev Pal

Baldev is a DevOps Engineer. He has Knowledge of Linux, AWS, Docker, Jenkins, Kubernetes, Terraform, and Git.

Request for Proposal

Name is required

Comment is required

Sending message..