Skip to content

This project is to build Kubernetes cluster on AWS using Terrafrom as IaC.

Notifications You must be signed in to change notification settings

DanielAtCosmicDNA/Terraform-Bulding-K8S

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform to Bulding Kubernetes Cluster using EC2 instances

LinkedIn Twitter Twitter

I build this project to create my own lab for Kuberntes cluster on AWS cloud using EC2 instances. I found Terraform is best tool to create my K8S lab fastly with one command 🚀.

Terraform

Terraform Resources Used

  • EC2
    • One Master Node
    • Two Worker Node (can be increased)
  • VPC
    • Public Subnet
    • Internet Gateway
    • Route Table
    • Security Group
  • S3 Bucket

How Will the Kubernetes Cluster Be Built?

The goals is to build K8S cluster with one master node and two worker nodes.

  • First, the master node will boots up and will start installing kubeadm, kubelet, kubectl, and docker. Then will run kubeadm init to initial the k8s cluster.
    Here the challenge become, how to get the join command that showed after init the cluster and send it to the workers node for joining the worker node into the cluster 🤔?
    To solve this problem I use s3 bucket. First I extract the join command and saved into a file, then push it to s3 object. Now we finish from master node and is ready.

  • Second, the workers node will boots up and will start installing kubeadm, kubelet, kubectl, and docker. Then will featch the joind command from s3 bucket and excuted to join the worker node into cluster.

Incress Number of Worker Nodes

  • By default there are two workers on the cluster, to incress it go to variables.tf file and looking for number_of_worker variable, you can incress the default number.

Requirements Before Running

1- Make sure you have the terrafrom tools installed on your machine.

2- Add your Access key, Secret key and Key Pair name on variables.tf file.

3- Make sure your IAM user has right permission to creating EC2, VPC, S3, Route Table, Security Group and Internet Gateway.

Running the Script

After doing the requirements, you are ready now, start clone the repo to your machine:

git clone https://github.com/DanielAtCosmicDNA/Terraform-Bulding-K8S
cd Terraform-Bulding-K8S/

Now execute terraform commands:

terraform init
terraform plan -out blueprint #to show what is going to be built
terraform apply "blueprint"

Finally, run the following script:

chmod +x ./scripts/after_terraform.sh
./scripts/after_terraform.sh

Accessing Your Cluster

  • You can access your cluster by accessing the master node throw ssh, you can get the public IP of master node from terrform outputs. Below is example of ssh command:
ssh -i "$SSH_KEY" "ubuntu@$KUBE_MASTER"
  • Another way to access the cluster by download the admin.conf file from master node to your machine. The download was already performed within the script after_terraform.sh. Therefore you can fastly use it by the following command to start accessing the cluster.
kubectl get nodes

Removing and Destroying Kuberntes Cluster

To destroy the hole resources that created after applying the script, just run the following command:

terraform destroy

Contact Me

Ahmad Faqehi - iAhmad.info - alfaqehi775@hotmail.com

Project Link: https://github.com/DanielAtCosmicDNA/Terraform-Bulding-K8S

About

This project is to build Kubernetes cluster on AWS using Terrafrom as IaC.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HCL 50.3%
  • Shell 49.7%