How to set up Kubernetes master-slave architecture?

M-Zohaib Nasir
3 min readMar 2, 2022

Today, we will set up a complete Kubernetes master-slave architecture using kubeadm. According to the kubeadm source, Kubeadm is a tool built to provide kubeadm init and kubeadm join as best-practice “fast paths” for creating Kubernetes clusters.

We will consider building a Kubernetes setup with one master node and 2 worker nodes.

Here we go,

Let us assume we have three Ubuntu Linux machines named kmaster and knode

1. Installing Docker as the container runtime Interface

On all the machines do the following:

#update the repository
sudo apt-get update

#Install docker
sudo apt install docker.io

#Start and automate docker to start at run time
sudo systemctl start docker
sudo systemctl enable docker

#verify docker installation
docker container ls

Kubeadm will by default use docker as the container runtime interface. In case a machine has both docker and other container runtimes like contained, docker takes precedence.

2. Installing kubeadm tool

#add the required repository for kubeadm
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF

#update the repository
$ sudo apt-get update

#installing kubelet, kubeadm and kubectl
sudo apt-get install -y kubelet kubeadm kubectl

#setting apt-mark
sudo apt-mark hold kubelet kubeadm kubectl

apt-mark will change whether a package has been marked as being automatically installed. Hold is used to mark a package as held back, which will prevent the package from being automatically installed, upgraded, or removed.

Restart the kubelet if required

systemctl daemon-reload
systemctl restart kubelet

3. Initializing the control plane or making the node as master(on master node)

kubeadm init will initialize this machine to make it a master.

Kubernetes assigns each node a range of IP addresses, a CIDR(Classless Inter-Domain Routing) block so that each Pod can have a unique IP address. We will specify the private CIDR for the pods to be created.

kubeadm init — apiserver-advertise-address=192.168.56.101 --pod-network-cidr=192.168.0.0/16

Now as seen in the output above, we need to run the below commands as a normal user to use the kubectl from terminal.

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Now the machine is initialized as master.

4. Joining Cluster

To join Kubernetes cluster simply copy that token at the end and paste it in worker node’s terminal in super user mode.


#something like this
kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>

That’s it!

To see all running pods,

kubectl get pods -o wide --all-namespaces

You would see all pods are running except DNS one. To resolve that problem, enable Calico network.

# on master node
kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml

Elaboration on Calico related issue:
You must deploy a Container Network Interface (CNI) based Pod network add-on so that your Pods can communicate with each other. Cluster DNS (CoreDNS) will not start up before a network is installed. We will use Calico as our CNI tool. Calico is a networking and network policy provider. Calico supports a flexible set of networking options so you can choose the most efficient option for your situation.

Conclusion:

We did it!

--

--