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:
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.
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.
Give root privilege
sudo su
to all the nodes.Make your system up-to-date with all the packages and versions. Type
apt update -y
. Do it in all the nodes.Make sure to install docker before going ahead
apt install
docker.io
-y.
Do it in all the nodes.systemctl start docker
to start the docker service.systemctl enable docker
to make sure of zero downtime even after booting the system up.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.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.apt update -y
This command again helps to keep the system up-to-date with newly installed packages.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.kubeadm init
execute this command only on the MASTER-NODE. (Do kubeadm init only to the master node)export KUBECONFIG=/etc/kubrnetes/admin.conf
cat /etc/kubrnetes/admin.conf
These commands are only to see the keys and documentation.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).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!
Subscribe to my newsletter
Read articles from Abhishek Bhagat. directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by