Kubernetes multi-node cluster over AWS using Ansible roles

Vikash kaushik
4 min readSep 17, 2021

--

What is K8S multi-node cluster?

A multi-node cluster is that where we use more than one worker nodes, so as to avoid single point of failure. Here is master node is connected to several worker nodes and this is called a multi-node cluster.

In this article I will show how to deploy a K8S multi-node cluster over AWS using Ansible roles.

Here we will deploy 2 worker nodes and a master node. I have used 3 different Ansible roles for launching the instances, master node configuration and worker node configuration.

GitHub => https://github.com/vikash232/Kubernetes_codes.git

Launching the ec2 instances-

Make sure to give the correct device name according to the cloud image used in role.

Configuring the master node -

Step 1 >Configuring Yum Repository for kubernetes.

Step 2 > Installing Docker, kubeadm and iproute-tc utility.

Step 3 > Starting and enabling Docker and kubelet. kubeadm is program that helps in the installation and configuration of Kubernetes cluster. We have configured yum repository for this.

kubelet -> A program that contacts the CRI (container Runtime Interface), for launching pods etc.

kubeadm -> kubeadm is program that helps in the installation and configuration of Kubernetes cluster. We configure yum repository for this.

kubectl -> It is used by the client to run the commands, that contact the API server on the master node for control of various resources.

Step 4 > Now we are pulling the images of k8s master

We pull the images that are required to run in containers on master node. They include kube control manager, kube api server , core dns , extd etc.

Step 5 > Now updating Docker cgroup on master node in daemon.js file

The docker engine by default uses cgroup driver which is not used by Kubernetes. We have to configure this file to use the systemd driver that is supported by Kubernetes. This is done by the blockinline module from Ansible.

Step 6 > Restarting docker to use systemd driver..

Step 7 > Now Initializing k8s cluster

Using the kubeadm init command, we initialize the master node. As I used t2.micro instance type and have limited RAM and CPUs, I had to give — ignore-preflight-errors option for NumCPU and Mem.

Step 8 > Creating some directories and copying the file into dir for setting up kubectl on master node.

Step 9 > Now we have to Deploying Flannel on Master Node

Step 10 > Creating token for worker nodes

Step 11 >Making some resources free and available for cluster.

Configuring the worker nodes -

Steps 1 to 6 are exactly same for both master and worker nodes.

Step 7 > Creating k8s.conf file.

Step 8 > Configuring ip-tables, we have to set them to one.

Step 9 > Run the command ‘sysctl — system’.

Step 10 > Now we are going to run joining the master node command.

Running the roles -

Configure the setup.yml file as this when running each role -

After attaching the roles path and configuring the ansible.cfg file,

My setup file:-

and run the roles by -

ansible-playbook <path-of-your-setup.yml>

Now go to master and run the command -

kubectl get nodes

We get

Here we see that our master node and the two worker node are Ready for any resources to deploy.

So, This is all our multi-node cluster is ready.

Thankyou for reading this blog. I hope you like it if you have any queries or suggestion do let me know in comment section. 😊

--

--