Ansible Role to configure Kubernetes Multi-Node Cluster over AWS Cloud

I know it is long article, assuming that reader knows what is Kubernetes, what are Ansible and Ansible-role, directly discussing the steps to create “Kubernetes Multi-node cluster using ansible-role over AWS cloud”.
Let’s have a look what to do
▶ 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.
▶ Convert Playbook into roles and upload those roles on your Ansible Galaxy.
Video url of this project: Click here.
Let’s jump to the steps:-
📌 First install the repository from GitHub or you can download role from Ansible-Galaxy also.
You can also read this installation process from
README.md
file. Click here.
- For
GitHub
, use the following command.
git clone https://github.com/Subhashis2/K8sMultiNodeClusterOnAws.git
- For
Ansible-Galaxy
, use the following command.
ansible-galaxy collection install subhashis2.k8smultinodeclusteronaws
- After that go to the
K8sMultiNodeClusterOnAws
directory.
cd K8sMultiNodeClusterOnAws
Warning!!..Do not run any program according to your choice. It may throw errors. Follow the steps, read the instructions carefully
- First make the
install.sh
file executable using the following command
chmod 755 install.sh
- Then run the
install.sh
file using the following command.
bash install.sh
- or, you can directly use this command.
./install.sh
- If everything runs successfully then read the given instructions carefully.

▶ Create Ansible Playbook to launch 3 AWS EC2 Instance
📌 First you have to download your AWS ec2-instance key-pair
in the provided location.
- Then run the following command.
chmod 600 <path_to_your_private_key_pair>
- Then update the location of key-pair in the ansible configuration file
/etc/ansible/ansible.cfg
.
cd /etc/ansible/ansible.cfg
vim /etc/ansible/ansible.cfg
- Then go to the
/ansibleWS
directory and open theinstanceDetails.yml
file using your favourite editor and fill it properly.
cd /ansibleWS
vim instanceDetails.yml

- Now it is the most important step, we have to do. We have to make
ansible-vault
to store the AWS IAM useraccess_key
andsecret_key
. Use the follow command to create vault and use the proper keywords, other wise it will through error in the program. UseawsIamKey.yml
name only, because it is hard-coded in the program.
ansible-vault create awsIamKey.yml
- Use this format only.
aws_access_key_id: <access_key>
aws_secret_access_key: <secret_key>
- After doing this steps successfully, run the following commands one after another. It can take more than 10 minutes, please make patience.
ansible-playbook --ask-vault-pass create_instances.yml
It will install
ec2-instances
as Master-Node and Worker-Nodes and will dynamically load the instances’ ip in the inventory file.

📌 create_instances.yml
▶ Ansible role to install docker application on the respective instances and configure K8S Master, K8S Worker Nodes.
📌 You just need to run setup.yml
file using following command.
ansible-playbook setup.yml
First it will run the
MasterNode
role to configure master-node, thenWorkerNode
role to configure worker-nodes, atleastDeployment
role to deploy a docker image and expose it to public world.

📌 setup.yml
📌 MasterNode/tasks/main.yml
📌 WorkerNode/tasks/main.yml
📌 Deployment/task/main.yml
After successfully running the
setup.yml
program, at the end, it will give some urls, you copy-paste this links on your browser and see the web-application is running. Sometime it takes 2-4 minutes to deploy, so wait for sometime.
http://<public_ip>:30080

Thank you everyone for reading this article.
Hope you guys like it.
Keep Learning, Keep Sharing.