Launching a Multi-Node Kubernetes Cluster using Ansible!

This blog will explain the process of launching a Multi-Node Kubernetes cluster using Ansible. The same Ansible code can be used to launch the same cluster on any platform whether it is cloud, bare-metal, etc., the only thing to change for launching the cluster on different platforms is the IP Address of the machines in the specified groups of Master & Worker nodes of Kubernetes.

Source: Exoscale

In this Agile/Automation World, we have to use automation for the task, because it not only saves a lot of time, but it also reduces the chances of mistake/human error which can be occurred by humans. For Example, if there are 100 machines that are to be configured, then there is a very high chance for human error in the configuration process. Therefore, to eliminate the error, we have to adopt automation tools like Terraform, Ansible, etc., based on the requirement/use-case. Here in this case Ansible is used because it is a configuration management tool & we have the use-case associated with configuration management only.

The complete process of the Kubernetes Multi-Node cluster is explained below with all the steps required. Here, Kubeadm is used to configure the cluster, with a kubelet program present on all the nodes for the communication between the PODS, & kubectl for running the Kubernetes Command.

Steps in the Configuration Pipeline

Configuration of the Master & Worker Nodes

  1. Configuring the Yum Repository for EPEL Packages (Extra software for future use).
  2. Configuring the Yum Repository for Docker Repository.
  3. Configuring the Yum Repository for Kubernetes Repository.
  4. Installing Docker.
  5. Installing Kubernetes.
  6. Stopping Firewall daemon.
  7. Disabling SELinux.
  8. Starting the Docker services.
  9. Installing python3 for docker-py Module and Pip3.
  10. Installing docker-py.
  11. Changing the Cgroup of docker from cgroupfs to systemd.
  12. Disabling Swap permanently after reboot.
  13. Adding Master & slave IP’s in the /etc/hosts file.
  14. Installing IpRoute-TC Package.
  15. Reloading systemd driver.
  16. Restarting Docker services.
  17. Starting & Enabling Kubelet services.
  18. Disabling the swap in the current scenario.
  19. Renaming the Kubernetes Master hostname to master.

Step 1: Configuring the Yum Repository for EPEL Packages!

Important Note: Use the proper indentation in the code as it is YAML Language code. Each & every piece code shown below is the proper indented code, that is why it is possible that some code might cut off from the screen as GitHub Gist has been used. To view complete code in one page, visit the link given at the end of this blog.

Step 2: Configuring the Yum Repository for Docker Repository!

Step 3: Configuring the Yum Repository for Kubernetes Repository!

Step 4: Installing Docker!

Step 5: Installing Kubernetes!

Step 6: Stopping Firewall daemon!

Step 7: Disabling SELinux!

Step 8: Starting Docker Services!

Step 9: Installing python3 for docker-py Module and Pip3!

Step 10: Installing Docker-py!

Step 11: Changing the Cgroup of docker from cgroupfs to systemd!

Step 12: Disabling Swap permanently after reboot!

Step 13: Adding Master & slave IP’s in the /etc/hosts file!

Step 14: Installing IpRoute-TC Package!

Step 15: Reloading systemd driver!

Step 16: Restarting Docker services!

Step 17: Starting & Enabling Kubelet services!

Step 18: Disabling the swap in the current scenario!

Step 19: Renaming the Kubernetes Master hostname to master!

Till here all the basic requirements for the configuration of the Master Node is complete, only the initialization & adding overlay network part is remaining for which a separate file is created, this part is covered ahead in this blog. But, keep in mind, we have to configure the worker nodes also, which is almost the same procedure, I am not covering that part here, because it will unnecessarily increase the complexity of the blog. For this remaining part, I would suggest to visit the link given at the end of this blog.

Steps to Initialize the Master Node

  1. Run the kubeadm command for the initialization.
  2. Create a directory, copy some files in that, & change the ownership.
  3. Add the flannel overlay network for the connection between PODS running on different containers.

Step 1: Running the Kubeadm Command!

Step 2: Creating & Transforming the required Directories!

Step 3: Adding the Flannel overlay network for communication between PODS!

Command to be executed after Initialization the Kubernetes Master! [Image by Author]

Running the PODS on the Worker Nodes

I hope my blog explains each and everything related to the Multi-Node Kubernetes Cluster setup with all the required code & explanation. Thank you so much for investing your time in reading my blog & boosting your knowledge!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Harshit Dawar

Big Data Enthusiast, have a demonstrated history of delivering large and complex projects. Interested in working in the field of AI and Data Science.