cover-img

Provisioning the Amazon EKS cluster using Terraform

creating terraform script to provision the AWS EKS Cluster

10 July, 2023

4

4

0

๐Ÿ™‹โ€โ™‚๏ธ Introduction

Hi folks, this is Ankit jodhani I recently graduated from university and currently exploring and learning DevOps and cloud with AWS. I have participated in the#10WeeksOfCloudOps challenge launched by Piyush Sachdeva.

This blog is 2nd part of "Deploying Dockerized App on AWS EKS Cluster using ArgoCD and GitOps methodology with CircleCI" Link

if you just want to provision the EKS cluster using Terraform then you can follow this blog independently.

โœ… Prerequisites

  • โŒ› Just need time to invest in learning
  • it would be great if you go through part 1 Link

๐Ÿ’ถ Note (Imp)

this is the 2nd blog of the Deploying Dockerized App on AWS EKS Cluster using ArgoCD and GitOps methodology with CircleCI

Blog 1 link: Click here

this is blog 2

Blog 3 link: Click here

Blog 4 link: Click here

๐Ÿ’ก Plan of Execution

  • ๐ŸŽฏ Architecture
  • ๐Ÿ–ฅ๏ธ local setup
  • ๐Ÿšจ IAM secret key
  • โœ๏ธ Writing terraform file
  • ๐Ÿคฉ Best practices
  • ๐Ÿ–จ๏ธ outputs
  • ๐Ÿ’ถ Note (Please checkout once)
  • ๐ŸŽ’ Resources

๐ŸŽฏ Architecture

let's see the architecture that we are going to build as part of this blog. I request you please go through it once. it helps you a lot while building this project.

๐Ÿ–ฅ๏ธ Local setup

๐Ÿง‘โ€๐Ÿ’ป VS Code

As a code editor, we'll utilize VS Studio. Please use this link to download it. It is incredibly portable and simple to use. Now, we're going to install the Terraform plugin in Visual Studio Code to increase your productivity. and the extension is called HashiCorp Terraform.

โš’๏ธ Terraform

Please install Terraform on your machine from this link. it's very easy to install and make sure to restart your system after installation.

๐ŸŒฅ๏ธ AWS CLI

To access the full functionality of AWS from your terminal, you must install AWS-cli. The download link is here.

๐Ÿšจ IAM secret key

I'm assuming you've set up all the programs and equipment. Time to launch the AWS console now. kindly visit the IAM service.

๐Ÿ’ Create USER

Please select the user tab from the menu on the left. to add a user, click the button in the upper right corner add user . You must now attach the user's policy. Although we should adhere to the principle of least privilege, we need to use many services to here you can give AdministratorAccess. however, it is not at all advisable. Instead, you should choose the list of services and attach the policy appropriately. click the next button now. , then select Create User button.

๐Ÿ’  Create a Secret key

select the user that you have created just now. click on the security credentials tab. below you will find an option with the name Create Acess key just click on it. after that select CLI and mark the checkbox below and click on the Next button, giving some description about it. and then click on the Create Access key button here you will see your Access Key ID and Secret Key. make sure you download it because you won't be able to see it once you close your window. and remember DO NOT SHARE THE KEY with anyone.

๐Ÿ’  Configure AWS-CLI

open the terminal on your system and type aws configure . it will ask for your Acess key ID and secret key id. please enter what we have just created. furthermore, it will ask output format JSON default region us-east-1 . you can enter the region where you want to deploy your app. Follow the below images to get more ideas.

โœ๏ธ Writing terraform file

Writing your infrastructure is now the final step. however, think twice before you act. To be clear, we're going to discuss best practices for developing code.

๐Ÿคฉ Best practices

  • store state files on a remote location (Amazon S3 service)
  • try to keep versioning for backups (Amazon S3 service)
  • state-locking (AmazonDynamoDB service)

please clone the repository. here is the link to the repo. or hit the below command.

git clone https://github.com/AnkitJodhani/kube_terraform-4thWeekOfCloudOps.git

let's understand the folder structure of the repository.

folder structure of the EKS using terraform

As you can see in the above image, we have two main folders inside the repository. We have the 'module' folder where all the modules are stored, and the 'todo-list-app' folder where I've imported and utilized all the required modules to build the infrastructure.

Let's set up the backend and state-locking. (You must have s3 bucket and Dynamodb table)

open todo-list-app/backend.tf

terraform {
backend "s3" {
bucket = "GIVE-YOUR-S3-BUCKET-NAME"
key = "backend/GIVE-ANY-NAME-TO-YOUR-BACKEND-FILE.tfstate"
region = "us-east-1"
dynamodb_table = "GIVE-DYNAMODB-TABLE-NAME"
}
}

Now you need to create one file in the todo-list-app folder with the name terraform.tfvars And paste the below content in the file. you can change the below configuration depending on your need.

REGION = "us-east-1"
PROJECT_NAME = "Todo-App-EKS"

VPC_CIDR = "192.168.0.0/16"
PUB_SUB_1_A_CIDR = "192.168.0.0/18"
PUB_SUB_2_B_CIDR = "192.168.64.0/18"
PRI_SUB_3_A_CIDR = "192.168.128.0/18"
PRI_SUB_4_B_CIDR = "192.168.192.0/18"

Please take note that the above file is crucial for setting up the infrastructure, so pay close attention to the values you enter for each variable.

it's time to build the infrastructure

let install dependency for the terraform. go inside the 'todo-list-app' folder and open the terminal. hit this command to initialize and install all the dependencies.

terraform init

The below command will tell you what terrafrom is going to create for you.

terraform plan

โœจFinally, HIT the below command to create the infrastructure...

terraform apply

type yes, it will prompt you for permission.

To view the source code, kindly go to my Github repository. and there you'll find directions on how to clone the repository and run it on your personal computer.

๐Ÿ–จ๏ธ Outputs

It's time to see the outputs. what terraform created for us on AWS.

๐Ÿ”น VPC

VPC created by terraform

๐Ÿ”น Subnets

Subnet created by terraform

๐Ÿ”น Internet gateways

Internet gateways created by terraform

๐Ÿ”น NAT gateway

NAT gateway created by terraform

๐Ÿ”น Route table and associations

Route table created by terraform

๐Ÿ”นIAM role for EKS cluster and Node Group

IAM role and policy created and attach by the terraform

๐Ÿ”นEKS Cluster

EKS cluster created by terrafrom

๐Ÿ”น Node group with t3.small type instance

Node group created by the terraform

Note: I've selected the t3.small instance type for the worker node but you can choose depending on your need. you can edit that in modules/Node-group/main.tf the file.

๐ŸŽ’ Resources

Terraform: https://developer.hashicorp.com/terraform/tutorials/kubernetes/eks

YouTube: https://www.youtube.com/watch?v=nIIxexG7_a8&list=PLiMWaCMwGJXkeBzos8QuUxiYT6j8JYGE5


Part 1:

Part 3: https://www.showwcase.com/show/35858/install-argocd-on-the-eks-cluster-and-configure-sync-with-github-manifest-repository

Part 4: https://www.showwcase.com/show/35858/install-argocd-on-the-eks-cluster-and-configure-sync-with-github-manifest-repository

๐Ÿ™ Thank you for reading this blog

๐Ÿ™‹โ€โ™‚๏ธ Ankit Jodhani.

๐Ÿ“จ reach me at ankitjodhani1903@gmail.com

๐Ÿ”— LinkedIn https://www.linkedin.com/in/ankit-jodhani/

๐Ÿ“‚ Github project repo https://github.com/AnkitJodhani/kube_terraform-4thWeekOfCloudOps.git

๐Ÿ˜บ Github https://github.com/AnkitJodhani

๐Ÿฆ Twitter https://twitter.com/Ankit__Jodhani

aws

azure

docker

git

github

devops

kubernetes

linux

yaml

developer

jenkins

learninpublic

cloud

terraform

flux

kyverno

fleet

100daysdevops

pulumi

linkerd

growtogether

eks

4

4

0

aws

azure

docker

git

github

devops

kubernetes

linux

yaml

developer

jenkins

learninpublic

cloud

terraform

flux

kyverno

fleet

100daysdevops

pulumi

linkerd

growtogether

eks

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

ยฉ Copyright 2024. Showcase Creators Inc. All rights reserved.