Sobes.tech
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:

  1. 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-daemonsets allows daemonset pods to remain on the node.
  • --delete-local-data deletes pods with local data, if any.
  1. Verify that all pods are evacuated:
kubectl get pods --all-namespaces -o wide | grep <node-name>
  1. 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.