top of page

How to Safely Drain and Delete a Node in Kubernetes Using kubectl

To delete a node in a Kubernetes cluster using kubectl, follow these steps:


  • Drain the Node: First, you should drain the node to safely evict all the pods running on it. This ensures that the workloads are gracefully moved to other nodes.

kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data

--ignore-daemonsets: This flag allows the drain command to ignore DaemonSet- managed pods, as they will be automatically managed by Kubernetes.

--delete-emptydir-data: This flag ensures that pods using emptyDir volumes are deleted, as these volumes can hold data that is not persisted.

  • Delete the Node: Once the node is drained, you can delete it from the cluster.

kubectl delete node <node-name>

This command removes the node from the cluster's control plane.


Example Commands

Assuming your node name is node-1, the commands would look like this:

  • Drain the Node:

kubectl drain node-1 --ignore-daemonsets --delete-emptydir-data
  • Delete the Node: sh Copy code kubectl delete node node-1


After deleting the node, you can verify that it has been removed by listing the nodes in your cluster:

kubectl get nodes

This command should show the remaining nodes in your cluster, confirming that the specified node has been successfully deleted.

Comments


bottom of page