How to remove a node from a Kubernetes cluster?
sobes.tech AI
Answer from AI
To remove a node from a Kubernetes cluster, follow these steps:
-
Drain the node from traffic routing:
kubectl drain <node_name> --ignore-daemonsets --delete-local-dataThis command "drains" the node, moving all pods not managed by DaemonSets to other nodes. The
--ignore-daemonsetsflag ignores DaemonSet pods, as they should run on every node. The--delete-local-dataflag deletes data on local volumes. -
Remove the node from the cluster:
kubectl delete node <node_name>This command removes the node's representation from the Kubernetes API but does not stop kubelet or Docker on the node itself.
-
Clean up the node: Run commands on the node itself to stop kubelet and remove its configuration files. The specific steps may vary depending on the tool used to create the cluster (kubeadm, kops, manually, etc.). For a cluster created with
kubeadm, these might be:// Stop kubelet sudo systemctl stop kubelet // Reset kubeadm state sudo kubeadm reset -
Disconnect the node from the infrastructure (optional): After removing and cleaning the node from the cluster, you can disconnect the virtual machine or physical server from the network if necessary.