Kubernetes with Ansible
Task __ Description:-
In this blog, we will perform the following tasks:
- Create Ansible Playbook to launch 3 AWS EC2 Instance.
- Create Ansible Playbook to configure Docker over those instances.
- Create Playbook to configure K8S Master, K8S Worker Nodes on the above created EC2 Instances using kubeadm.
So first we will be creating a directory for ansible-playbook and make roles in that folder -
#mkdir ansible-playbook
#cd ansible-playbook
#ansible-galaxy init
aws_provision
#ansible-galaxy init
cluster_setup
After this inside the aws_provision we will see for present folders. then inside the tasks folder, we will create our playbook in main.yml.
Then open the main.yml inside vars folder to give the slave count.
As we can observe there is no instance in the AWS cloud, so we'll have to run the aws_provision role to launch the instances. So create a yml file in the ansible-playbook folder and execute it.
Now, our playbook has successfully executed and we have three running containers named Master, slave-1, slave-2.
Create Ansible Playbook to configure Docker over the previously launched instances -
Now go to the cluster_setup role and write your code in tasks/main.yml
In the above playbook, we first configured the yum repository and then installed the packages docker, kubeadm, kublet, kubectl. After that, we have to edit the daemon.json file so we have to restart our docker services and install Iproute-tc.
Then we have to configure master using kubeadm so for that we pull the image and for worker node we have to copy the admin file, paster the token file and run the token file. For that open cluster_Setup and go to files folder
#cd cluster_setup
#ls
#cd files
After making all those changes we will run our k8s.yml playbook for cluster_setup
#ansible-playbook k8s.yml
Comments
Post a Comment