DEV Community

Nnamdi Kenneth Nwosu
Nnamdi Kenneth Nwosu

Posted on

How To Setup Kubernetes Cluster with master and worker node ( kubelet, kubeadm and kubectl)

  1. Create Two Ubuntu VM (MASTER AND WORKER): and SSH Into them using the link here

  2. Install Docker Engine on both VM and enable Docker:

sudo apt-get install -y docker.io
sudo usermod –aG docker Ubuntu
sudo chmod 777 /var/run/docker.sock

sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker
Enter fullscreen mode Exit fullscreen mode
  1. Installing kubelet, kubeadm and kubectl:
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
Enter fullscreen mode Exit fullscreen mode

Download the public signing key for the Kubernetes package repositories. The same signing key is used for all repositories so you can disregard the version in the URL:

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
Enter fullscreen mode Exit fullscreen mode

Add the appropriate Kubernetes apt repository.

echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
Enter fullscreen mode Exit fullscreen mode

Update the apt package index, install kubelet, kubeadm and kubectl, and pin their version:

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Enter fullscreen mode Exit fullscreen mode

Enable the kubelet service before running kubeadm

sudo systemctl restart kubelet
sudo systemctl status kubelet
sudo systemctl status kubelet
Enter fullscreen mode Exit fullscreen mode

Adding kubeadm to a network (ON THE MASTER VM ONLY)

sudo kubeadm init --apiserver-advertise-address=(PRIVATE IP OF VM) --pod-network-cidr=192.168.0.0/16
Enter fullscreen mode Exit fullscreen mode

Adding kubenetes cluser:

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

Back on WORKER NODE:
Follow the same process to - Install kubelet, kubeadm and kubectl:

Join the Master and Worker with the Join Command:

  • Using the JOIN Command looks like this on the vm
sudo kubeadm join 172.31.56.164:6443 --token y82mmu.a9wairsns2hhrgtu \
        --discovery-token-ca-cert-hash sha256:fd617bad969a4275a7a8d03c6bcb3a9a115196feb14c27ffc5371495e1dc6f84

Enter fullscreen mode Exit fullscreen mode

to retrive the join command incase you didnt save it run this on Master VM

kubeadm token create --print-join-command
Enter fullscreen mode Exit fullscreen mode

To test on Master VM:

kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

its show node NOT READY.

Set your port network Using Calico manifest:
click here for doc info

curl https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/calico.yaml -O

kubectl apply -f calico.yaml
Enter fullscreen mode Exit fullscreen mode

Run these commands on MASTER

kubectl get nodes
kubectl get pod -A
Enter fullscreen mode Exit fullscreen mode

Create a pod to TEST:

kubectl run my-pod --image=nginx 
kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Thank You for Following and Practicing.

Top comments (0)