Hello Guys 🙋♀️ In this article we are going to perform the following task.
Task Description:
Ansible Role to Configure K8S Multi-Node Cluster Over AWS Cloud.
🔰 Create Ansible Playbook to launch 3 AWS EC2 Instance
🔰 Create Ansible Playbook to configure Docker over those instances.
🔰 Create Ansible Playbook to configure K8S Master, K8S Worker Nodes on the above created EC2 Instance using kubeadm.
Let's start the practical…….
Firstly we are going to launch 3 Instances on top of AWS by using an ansible-playbook. One instance will act as Master and the other two will act as a Worker node.
Firstly you need to set up ansible on top of AWS. After setting the ansible cluster we need to create an inventory file and configuration file.
This is our configuration file.
Inside the Inventory file, we need to add the IPs of the system on which we want to configure the cluster.
We are going to create Ansible Role for launching Instance and for setting Master and Worker node.
So let's first create a role
We are going to create one directory and inside that directory, we will create our role.
It will Create the EC2_Instance role.
By installing tree you can see the hierarchy.
Now you can see roles are resided inside the playbook and roles contain our EC2_Instance role. Inside the tasks folder, we need to create the main.yml playbook. similarly, we need to create a role for Kubernetes Master ad Worker also.
On the level of roles, we need to create a playbook named master.yml which will contain hosts and roles. At final we are going to run this playbook.
Let's First write a playbook for launching instances
As we need to use the access key and secret key while launching the instances so it is important to secure them. for that purpose, we are going to use the vault.
In this case file, newkeys.yml contains the access key and secret key.
After applying vault you can see the above output. make sure that the file that contains an access key and secret key must be at the same level as master.yml means in the playbook folder.
You need to add the following lines in master.yml
Let's run the playbook now. Ansible master itself is the host for running the playbook of EC2 Instances.
After running this playbook you can see our launched instances on the dashboard.
Inventory file:
Now we are going to write the playbook for Master Node
daemon.json file
kubernetes.repo
we need to create token.yml inside the playbook folder for storing the token.
master.yml for
Following should be the contents of the playbook folder
Let's run master.yml
our playbook has run successfully.
After running the playbook you can see our token is store in the join_token file
Playbook for Worker Node
master.yml file for worker
Let's run master.yml
Our playbook has run successfully.
Let's check whether it is working or not. so go to Kubernetes Master Node and check this.
After running the get nodes command you can see our cluster has set up successfully.
Thanks For Reading😊😊😊