Hi there! Hope you are doing well. Today we are going to set up a Kubernetes Multi-node cluster on top of AWS using one of the best configuration management tool called Ansible.
Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning.
I have already written some blogs on the basics of Ansible and AWS. You can check them out too.
Let's start
Our setup will be like this:
One EC2 instance will act as a master/control-plane.
Two EC2 instances will act as two workers/slave nodes.
For these, I will be writing ansible roles instead of the playbook as roles are a better way to manage code. Now both master and worker nodes have some common configuration that needs to be done so for that I created a common role which we will apply on all nodes of the cluster and then we will apply master specific role on the master node and worker specific role on worker nodes.
In short, I have created three roles:
- Common Role
- Master Role
- Worker Role
Here's a little peak how they look like :
Now we will create a simple playbook to launch instances and then apply these roles accordingly. Here's the playbook.
I have used vars_file to store the variables needed for setting up EC2 instances and also we need AWS IAM credentials to launch instances which I have stored in the credentials file and encrypted them to provide security.
You can view all code here
Now let's run the playbook. For running, if you have used the ansible-vault to encrypt the AWS credentials then we need to provide the vault password to the playbook using
ansible-playbook --ask-vault-pass main.yml
Our playbook ran successfully. Now let's check the same in the AWS console.
Now let's go inside the master node and see if all things are up and working.
Our Kubernetes cluster has been successfully configured now. In this way, we use the power of Ansible to configure and setup environments with just one click.
That's it for this blog and see you next time ...!!