Sitemap

Configure K8S Multi-Node Cluster over AWS using Ansible

5 min readJun 21, 2021
Press enter or click to view image in full size

Lets first introduce about the file structure that
“How I am going to configure it ?”
So, I have made the four roles :-
1. For launching the instances
2. Configuring the Common Setup which need on Both Nodes i.e master and slave.
3. Configuring the master node (like initializing master , configuring flannel etc . . . .)
4. Configuring the Slave node ( like joining with cluster . . . .)

If You Don’t Know About role or How to convert your playbook to role ?
First I would recommend that you should must read the given blog first then proceed . . .

How we can convert our ansible PlayBook to Role ? 🤔

We Will Also Going To Share that on Ansible Galaxy !! 🤔

Lets Start !
Step 1: First Launch the Instance for the master and slave (according to your requirement).

In my case I am going to launch 1 instance for the master and 2 or 3 for the slave. Link of the role given below :

Ansible Galaxy

Jump start your automation project with great content from the Ansible community

galaxy.ansible.com

Shashwatsingh22/instance_ec2

A brief description of the role goes here. Any pre-requisites that may not be covered by Ansible itself or the role…

github.com

You can change the variable according your requirement .
Master →

Slave →

Run the Play →

Press enter or click to view image in full size
Press enter or click to view image in full size

Step 2: Understand the Second Role Which will configure the both instances master as well as slave node .

Shashwatsingh22/k8s_cluster

Ansible Collection — . Contribute to Shashwatsingh22/k8s_cluster development by creating an account on GitHub.

github.com

Ansible Galaxy

Jump start your automation project with great content from the Ansible community

galaxy.ansible.com

1> First Configure , Install and Start the service Docker.

2> Configuring the yum for the installation of the required software’s like kubectl , kubelet , kubeadm

3> Disabling the Security of the SElinux for the smooth configuration k8s cluster .

4> Installing the Important Software’s like kubeadm, kubelet ,kubectl and Starting the kubelet Service.

5> Pulling the images which will manage our cluster.

6> Changing the Driver of the Docker and restarting the docker service.

6> Installing the iproute-tc

Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size

Step 3: Now the third role come in play which will configure the master.

1> Setting bridge-nf-call-iptables = 1

2> Initializing Master

3> Creating the .kube directory ,
Copying the /etc/k8s/admin.conf$HOME/.kube/config &&
Changing the owner permission of $HOME/.kube/config

4> Genrating token and storing it . When it need to join the slave to cluster.

5> Adding the Flannel Overlay NetWork for the Communication.

Press enter or click to view image in full size

Step 3: Now the Fourth role come in play which will configure the slave.

1> Setting bridge-nf-call-iptables & ip6tables to 1.

2> Retrieving the token and joining the slave to the Cluster

Now ! Here We have complete the SetUp Of the K8s Cluster .

→Lets Go And Interact with master and run the command to ensure that
“How many nodes are connected the master ?”

$ kubectl get nodes
Press enter or click to view image in full size

Hope You Enjoy this Automation ! !

Thank You !!

Shashwat Singh

Cyber Security Enthusiasm || Docker || RHEL8 || Working On Web Development || CTF Player || Machine Learning || Flutter Developer || Ansible || K8s

Follow

1

1

More from Shashwat Singh

Follow

Cyber Security Enthusiasm || Docker || RHEL8 || Working On Web Development || CTF Player || Machine Learning || Flutter Developer || Ansible || K8s

Mar 30

Create An Ansible Playbook to Retrieve the Container IP and update the Inventory File & Configure the Webserver.

Lets First Build An Docker Image In Such A way so that we can do SSH to it . . .
We can do either Manually or by the help of DockerFile ;

Read more · 3 min read

Mar 29

Configure The LoadBalancer On EC2 Instance !!

Lets Start😎 !!

Lets Write an Dynamic Playbook In Such a way we can lunch the Instance as Per Our Need.
→ Launch the 3 Instances for the Web-Server -

- hosts: localhost
become: Falsevars_prompt:
- name: noOS
private: no
prompt: "How Many Instances Do You Wants Lunch ?"vars_files:
- awsAccess.ymltasks:
- name: Launch instance for webserver
ec2:
count: "{{ noOS }}"
group_id: "sg-0d4c5f0d452e1b620"
image: "ami-08e0ca9924195beba"
aws_access_key: "{{ usern }}"
aws_secret_key: "{{ pass }}"
instance_type: "t2.micro" …

--

--

No responses yet