Ansible Role to Configure k8s Multi Node Cluster over AWS Cloud.
Created a k8s multinode cluster over AWS cloud, then created an Ansible Playbook to launch 3 AWS EC2 Instance, Ansible Playbook to configure Docker over those instances & created Playbook to configure k8s Master, k8s Worker Nodes on the above created EC2 Instances using kubeadm.
Created a WorkSpace for all the practicals to be done which would be more manageable.
Created a Configuration File.
So, I want all the IP to be fetched from AWS.
To achieve that I will be using dynamic inventory instead of static inventory.
To create Dynamic Inventory .
- Step 1
Created a directory named dynamic_inventory
- Step 2
As, we all know Ansible is created on top of the python, So it has the capability to fetch IP from the python file.
In that folder, I downloaded and created two files.
This command will create a ec2.py dynamic inventory file
This command will create a ec2.ini dynamic inventory file
- Step 3
We need to make those two files executable.
chmod +x ec2.py
chmod +x ec2.ini
- Step 4
In ec2.py file, I added an interpreter name on the top , and then commented the 172th line.
In ec2.ini file, I added aws_access_key_id and aws_ secret_access_key and the region .
Now I provided environmental Variables.
- STEP 6
Looking for the all the hosts on AWS Cloud .
Used ping module in adhoc command to check the connectivity.
Now, We are done with dynamic inventory.
Created the role for multiple used cases step by step as following
- For Launching a VPC, Igw, Subnet, Route table
- Provisioning an AWS ec2 Instance in that VPC.
- Configuring Kubernetes master on one of the instance.
- Configuring Kubernetes slave on two of the instance.
- Launching Wordpress & mysql server on kubernetes slave by using k8s Master node.
Playbook to launch a VPC on AWS and ec2 instance simultaneously.
Playbook to launch kubernetes cluster ie, master-slave model and then launch Wordpress & mysql simultaneously.
VPC, Subnet, Internet Gateway, Route Table and ec2 instance now has been successfully created.
Next, I have updated the details WordPress required and then providing MySQL details, It brings to the end of my practical and leads to the great used cases to be solved.