Sobes.tech
Middle

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:

  1. Drain the node from traffic routing:

    kubectl drain <node_name> --ignore-daemonsets --delete-local-data
    

    This command "drains" the node, moving all pods not managed by DaemonSets to other nodes. The --ignore-daemonsets flag ignores DaemonSet pods, as they should run on every node. The --delete-local-data flag deletes data on local volumes.

  2. 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.

  3. 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
    
  4. 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.