Provisioning Kubernetes Cluster

Provisioning Kubernetes Cluster

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:

On_premise_deployments.png

  • 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 :

VirtualBox_Ansible Controller Redhat_16_03_2021_15_52_59.png

Now we will create a simple playbook to launch instances and then apply these roles accordingly. Here's the playbook.

Screenshot (1119).png

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.

Screenshot (1120).png

VirtualBox_Ansible Controller Redhat_16_03_2021_16_17_40.png

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

VirtualBox_Ansible Controller Redhat_16_03_2021_15_41_24.png

VirtualBox_Ansible Controller Redhat_16_03_2021_15_41_56.png

VirtualBox_Ansible Controller Redhat_16_03_2021_15_42_25.png

Our playbook ran successfully. Now let's check the same in the AWS console.

Screenshot (1116).png

Now let's go inside the master node and see if all things are up and working.

Screenshot (1118).png

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 ...!!

Did you find this article valuable?

Support Written Wisdom by becoming a sponsor. Any amount is appreciated!