Chapter 6
Uninstall and Remove
Step 1: Remove the Node from the Cluster
-
Mark the Node as Unschedulable
kubectl cordon kube-worker-3
-
Drain the Node:
kubectl drain kube-worker-3 --ignore-daemonsets --delete-local-data
-
Delete the Node:
Remove the node from the Kubernetes cluster:
kubectl delete node kube-worker-3
Step 2: Clean Up Flannel and CNI Configurations on the Node
Execute the following steps on the node to clean up Flannel and CNI configurations:
-
Stop and Disable kubelet and containerd Services:
sudo kubeadm reset sudo systemctl stop kubelet sudo systemctl stop containerd sudo systemctl disable kubelet sudo systemctl disable containerd sudo apt-get remove kubelet kubeadm kubectl
-
Remove Flannel Configurations and Data:
sudo rm -rf /var/lib/cni/ sudo rm -rf /var/lib/kubelet/* sudo rm -rf /etc/cni/ sudo rm -rf /run/flannel/
-
Remove CNI Configurations and Data:
sudo rm -rf /etc/cni/net.d/ sudo rm -rf /var/lib/cni/ # sudo rm -rf /opt/cni/bin/
-
Remove containerd Data:
sudo rm -rf /var/lib/containerd/ sudo rm -rf /etc/kubernetes/kubelet.conf sudo rm -rf /etc/kubernetes/pki/ca.crt # sudo rm -rf /etc/systemd/system/containerd.service.d/http-proxy.conf # sudo rm -rf /etc/kubernetes/bootstrap-kubelet.conf
-
Reboot the Node:
sudo reboot
-
Verify the Cleanup
Use the following command to verify that the node has been removed from the Kubernetes cluster:
kubectl get nodes
-
Verify the Cleanup is Complete:
sudo ls /var/lib/kubelet sudo ls /etc/cni/net.d/ sudo ls /opt/cni/bin/ sudo ls /var/lib/containerd/
If these directories do not exist or are empty, the cleanup is complete.
Reset Control Plane
kubeadm reset
sudo rm -rf /etc/cni/net.d/
sudo rm -rf /var/lib/cni/
sudo rm -rf $HOME/.kube/config
sudo reboot