Skip to main content

Overview

In this document, we will ensure our existing Kubernetes cluster works with high availability along with uninterrupted service by routing to virtual IP without breaking it. Existing Machines:
  • Kubernetes Master1
  • Kubernetes Master2
  • Kubernetes Master3
  • Kubernetes Worker1
  • Kubernetes Worker2

Existing System and Virtual IP Access

In the existing system, a Kubernetes cluster started with kubeadm init command on Master1 was created and then other machines (Master2, Master3, Worker1, and Worker2) were included in this cluster with worker role. By defining a Virtual IP on Load Balancer, we need to access existing machines to this Virtual IP from 6443 port.
If you are not using a load balancer and cannot create a virtual IP on the network, click here to perform this operation with Keepalived and HAProxy tools you can use for this.Keepalived is used to create virtual IP, HAProxy is used for load balancing operation.

IP Change

When there are multiple master nodes in the cluster, we need to reconfigure the cluster to leave these masters as a single master. This operation usually starts by completely removing other masters from the cluster.

Removing Master Nodes from Cluster

The following command is run for other masters (master2 and master3) except master1.
sudo kubeadm reset
Other masters (master2 and master3) are deleted from the cluster from Master1 server.
kubectl delete nodes master2
kubectl delete nodes master3
Master1 and worker servers should remain in the existing system.

Tasks to be Done on Master1 Server

1
Stopping ServicesKubelet and containerd (and docker application if docker is used) are stopped.
sudo systemctl stop kubelet
sudo systemctl stop containerd
2
File Backup and CleaningBackups of some files are taken and deleted.
sudo mv -f /etc/kubernetes /etc/kubernetes.backup
sudo mv -f /var/lib/kubelet /var/lib/kubelet.backup
sudo mkdir -p /etc/kubernetes/pki
sudo cp -r /etc/kubernetes_backup/pki /etc/kubernetes
sudo rm -rf /etc/kubernetes/pki/{apiserver.*,etcd/peer.*}
sudo rm -f ~/.kube/config
3
Starting ContainerdContainerd (and docker application if docker is used) is started.
sudo systemctl start containerd
4
Virtual IP Configuration with Kubeadm InitKubeadm init command is run again by editing endpoint address and used as Virtual IP.
sudo kubeadm init --pod-network-cidr "10.244.0.0/16" --control-plane-endpoint <VIRTUAL_IP> --upload-certs --ignore-preflight-errors=DirAvailable--var-lib-etcd
Kubeadm join commands are noted.

Tasks for Worker1 and Worker2

1
Stopping ServicesKubelet and containerd (and docker application if docker is used) are stopped.
sudo systemctl stop kubelet
sudo systemctl stop containerd
2
File BackupBackups of some files are taken.
sudo mv -f /etc/kubernetes /etc/kubernetes.backup
sudo mv -f /var/lib/kubelet /var/lib/kubelet.backup
3
Starting ServicesContainerd (and docker application if docker is used) and kubelet are started.
sudo systemctl start kubelet
sudo systemctl start containerd
4
Worker JoinKubeadm worker join command is run on worker1 and worker2 machines.

Tasks for Master2 and Master3

In this step, it will be sufficient to just run the master join command on master2 and master3.

Cluster Status Check

You can see your new cluster information with the following commands.
kubectl cluster-info
kubectl get node -o wide