Build Kubernetes Cluster with Kubeadm: A Step-by-Step Guide for Beginners

In this blog, I'm going to cover a Step-by-step guide to set up a Kubernetes cluster with both master node and worker node, get ready to make your deployment production-friendly.

What is kubeadm?

Kubeadm is a command-line tool specifically designed for setting up production-ready Kubernetes clusters. It's used to initialize and manage multi-node Kubernetes clusters.

Why kubeadm?

It's suitable for creating clusters that will be used in a production environment, where you want to customize configurations and deploy on different nodes.

Kubeadm helps with tasks like setting up the control plane components, joining worker nodes, and ensuring that the cluster conforms to best practices.

Prerequisites for creating Kubernetes clusters using Kubeadm:

  • For the master node, it requires Ubuntu EC2 t2.medium which is a paid service.

  • For worker nodes Ubuntu EC2 t2.micro which comes with free tiear.

  • Make sure you have docker installed in your both systems (master and worker)

  • For permission-related problems further give it root privilege.

Follow these steps to successfully install and setup Kubernetes clusters using kubeadm:

  1. MASTER-NODE: Create an EC2 instance for the master node of t2.medium because it provides a sufficient amount of CPU required by kubeadm, this is the paid service of AWS.

  2. WORKER NODE: To set up a worker node you need an EC2 t2.micro instance(free service )and you can have as many worker nodes as you want.

  3. Give root privilege sudo su to all the nodes.

  4. Make your system up-to-date with all the packages and versions. Type apt update -y. Do it in all the nodes.

  5. Make sure to install docker before going ahead apt install docker.io -y.Do it in all the nodes.

  6. systemctl start docker to start the docker service.

  7. systemctl enable docker to make sure of zero downtime even after booting the system up.

  8. curl -fsSL "https://packages.cloud.google.com/apt/doc/apt-key.gpg" | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/kubernetes-archive-keyring.gpg this command will bring all the necessary packages from googles directory.

  9. echo 'deb https://packages.cloud.google.com/apt kubernetes-xenial main' | sudo tee /etc/apt/sources.list.d/kubernetes.list This command ensures the signature.

  10. apt update -y This command again helps to keep the system up-to-date with newly installed packages.

  11. apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y This command installs kubadm, kubectl and kubelet with their respective versions.

  12. kubeadm init execute this command only on the MASTER-NODE. (Do kubeadm init only to the master node)

  13. export KUBECONFIG=/etc/kubrnetes/admin.conf

  14. cat /etc/kubrnetes/admin.conf These commands are only to see the keys and documentation.

  15. kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml This command applies or creates the network (weavework).

  16. kubeadm token create --print-join-command This command creates a token for all the worker nodes to join. (Do this only to the master node).

copy the token generated and paste it over the worker nodes and you are done with the Kubernetes cluster setup using Kubeadm.

Don'ts for the worker node:

  • Don't write kubeadm init on WORKER-NODE.

  • kubeadm token create --print-join-command this command creates token for all the worker nodes to join, this should only execute on MASTER-NODE.

With these steps, your Kubernetes cluster should be up and running. You've successfully used Kubeadm to set up a master node, added worker nodes, and established a functional network. Enjoy exploring the capabilities of your new Kubernetes environment!

0
Subscribe to my newsletter

Read articles from Abhishek Bhagat. directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abhishek Bhagat.
Abhishek Bhagat.