This repository contains the Terraform code to deploy infrastructure on AWS. It includes creating a VPC with three public and three private subnets, launching EC2 instances in the public subnet as a BastionHost, and creating Private EKS Cluster .
The following diagram represents the architecture of the project:
This project uses Terraform to create the following AWS resources:
- VPC
- Internet Gateway
- Public Route Table
- Private Route Table
- Public EC2 instance
- NatGateway and ElasticIP
- Security Groups
- Node group
- EKS role and policy
- Node Group Role and Policy
- EKS Cluster
To get started with this project, clone this repository to your local machine:
$ git clone https://github.com/elmansey/Terraform_EKS_Cluster.git
Before running the deployment script, you will need to have the following:
- AWS account
- Terraform installed on your local machine
- AWS credentials configured on your local machine
- ssh on your local machine to connect to BastionHost to access from it the private cluster
- A Secret Manager in AWS to store aws credentials stored(aws_access_key_idaws_secret_access_key) to but them in bastion host to connect to cluster by it
- A S3 bucket to store the Terraform state file, and DynamoDB to use for state locking. You can include them in
remoteBackend.tf
-
Navigate to the project directory:
$ cd Terraform_EKS_Cluster -
Initialize the Terraform configuration:
$ terraform init
-
Apply the Terraform configuration:
$ terraform apply
The following variables can be defined in the terraform.tfvars file:
eksName: a string representing the EKS namenode_group_name: a string representing the node group nameami_type: a string representing the ami typecapacity_type: a string representing the capacity type such as ON_DEMANDdisk_size: a Number representing the cluster disk sizeinstance_types: a list representing the instance type such as["t2.small"]desired_size: a Number representing the the desired size for node in clustermax_size: a Number representing the max_size cluster nodemin_size: a Number representing the min_size cluster nodemax_unavailable: a Number representing the max_unavailable node in the cluster
public_subnet_cider: a list representing the public_subnet_cider such as["10.0.1.0/24","10.0.2.0/24","10.0.3.0/24"]private_subnet_cider: a list representing the private_subnet_cider such as["10.0.4.0/24","10.0.5.0/24","10.0.6.0/24"]availability_zones: a list representing the availability_zones such as["us-east-1a", "us-east-1b", "us-east-1c"]prefix: a string representing the comany prefixvpc_cider: a string representing the vpc_cider such as"10.0.0.0/16"Kubernetes_version: a string representing the Kubernetes_version such as"1.25"
instance_type: a string representing the instance type such as"t2.small"region: a string representing the region such as"us-east-1"terraform_user_secret_arn: a string representing the terraform user secret arn
With this Terraform code, you can create a VPC with three public and three private subnets in three different availability zones, launch EC2 instance as a bastionHost for accessing the private cluster.
