Junior — Middle
How can you safely and effectively exclude a node from an active Kubernetes cluster?
sobes.tech AI
Answer from AI
To safely and effectively remove a node from an active Kubernetes cluster, follow these steps:
- Drain the node — puts the node into a state where no new pods are scheduled on it, and existing pods are gracefully terminated and rescheduled on other nodes:
kubectl drain <node-name> --ignore-daemonsets --delete-local-data
--ignore-daemonsetsallows daemonset pods to remain on the node.--delete-local-datadeletes pods with local data, if any.
- Verify that all pods are evacuated:
kubectl get pods --all-namespaces -o wide | grep <node-name>
- Remove the node from the cluster (if necessary):
kubectl delete node <node-name>
This way, you first properly shut down the pods on the node, preventing data loss and failures, and then remove the node from the cluster.