How to setup Multi Node k8s Cluster on AWS using Ansible | Technical EJ - Latest Technology News

Thursday 27 May 2021

How to setup Multi Node k8s Cluster on AWS using Ansible

  Ekansh Jain       Thursday 27 May 2021

Hello Everyone, today I am going to explain how to setup a Kubernetes Multi-Node cluster on AWS Using the Ansible tool.

Kubernetes Multi-Node cluster on AWS Using Ansible
Kubernetes Multi-Node cluster on AWS Using Ansible

Steps to be followed:

1) First, we are going to launch 2 instances, one is for Master Node and another one is for Worker Node and in this practical, we will configure the client system in the master Node itself to save our time.

2) Then we will create two playbooks for launching two ec2 instances on the AWS cloud with the dynamic inventory.


Master Node Instance
Master Node Instance

Worker Node Instance
Worker Node Instance

How to Setup Dynamic Inventory in Ansible

For a dynamic inventory, we have to download the ec2.py and ec2.ini files, these files help us to maintain the inventory of ansible for every upcoming ec2 instance.

After downloading, move these files to the inventory folder of Ansible

Link to Download: EC2 files

ec2 files
ec2 files

3) Then we will create two different roles for Master Node and Worker Node.

Master Node Role
Master Node Role

Worker Node Role
Worker Node Role

How to Configure the Master Node

1) First, we will download the docker software so that we can launch the container on top of the docker and download the iproute-tc software to setup the group's drivers and iptables.

2) Then, start the service of Docker so that further, we can use this software.

3) Now, for configuring the Kubernetes, we have to configure the repository of yum, so for configuring the Kubernetes, we will use the yum_repository module.

Configuration setup of Master Node
Configuration setup of Master Node

4) Then we will download the kubeadm software, it will help to setup the cluster and it will provide the kubelet and kubectl.

Here, kubelet is an agent program that is present on every Nodes and kubectl is a client program that runs the commands against the cluster.

5) Then we will start the service of kubelet program.

6) Then we will copy the daemon.json file.

Configuration Setup
Configuration Setup

Daemon.json
Daemon.json

7) Then we will initiate the process of Multi-Node Cluster by running the command shown below in the image.

8) Then the kubeadm init command gives the further steps to do (further commands help to create the client).

9) Then, to run all the pods, we will run the Kube-flannel.yml file.

Note: Flannel is a CNI Plugin that helps in the networking and it is an overlay network that satisfies the requirement of Kubernetes.

Configuration Setup
Configuration Setup

10) After following the above steps, we will create a token so that the Worker Node can join the Master node using this token.

11) We will store the token in the dummy host using the add_host module.

Configuration Setup
Configuration Setup

Master Node Instance launched
Master Node Instance launched

How to Configure the Worker Node

1) First, we will download the docker software and iproute-tc software so that we can launch the container on top of the docker

2) Then, start the service of Docker, so that further, we can use this software

3) Now, for configuring the Kubernetes, we have to configure the repository of yum, so for configuring the Kubernetes, we will use the yum_repository module.

Configuration Setup of Worker Node
Configuration Setup of Worker Node

4) Then we will download the kubeadm software, it will help to setup the cluster and it will provide the kubelet and kubectl.

5) Then we will start the service of kubelet Program.

6) Then we will copy the daemon.json file.

Configuration Setup
Configuration Setup

7) Now, we will update the value of iptables from 0 to 1 using sysctl module present in Ansible.

Now, we are all set, now we copy the token from the master Node and paste it into the worker node so that the Worker Node can join Master Node.

Configuration Setup
Configuration Setup


Worker Node Instance Launched
Worker Node Instance Launched

Now, we will create one yml file which uses these two roles as shown below.

Includes both roles
Includes both roles

Here, we used the include_role option, because we want to run the playbook at the task level.

Both Nodes has been launched
Both Nodes has been launched

Master Node Setup Done
Master Node Setup Done


Final Output of the Playbook
Final Output of the Playbook

Complete Setup Done

Now, the Complete Setup of a Multi-node cluster of Kubernetes on AWS has been done.

Hurray!!!! 

We are done with our amazing Setup.


Github Link: https://github.com/technicalej/Multi-Node-Cluster-of-k8s-on-AWS

Worker Node Role: https://galaxy.ansible.com/technicalej/k8s_setup_of_worker_role

Master Node Role: https://galaxy.ansible.com/technicalej/k8s_setup_of_master_role

logoblog

Thanks for reading How to setup Multi Node k8s Cluster on AWS using Ansible

Previous
« Prev Post

No comments:

Post a Comment

If you have any doubts, Please Comment down