Removing a Node - gpillon/k4all GitHub Wiki

When you need to remove a node from your Kubernetes cluster, follow these steps to ensure it is properly disconnected and removed from both Kubernetes and the etcd datastore.

Step 1: Drain the Node

First, you must drain the node to ensure that all the running pods are safely evicted. This can be done using the following kubectl command:

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

Replace with the actual name of the node you wish to remove.

Step 2: Delete the Node

After the node has been drained, you can remove it from the cluster by running:

kubectl delete node <node-name>

Step 3: Get all remaning etc pods

kubectl get pods -n kube-system | grep etcd

and write down the etcd-pod-name (eg. "etcd-kube-control-a1010")

Step 4: Get all members

kubectl exec <etcd-pod-name> -n kube-system -- etcdctl --cacert /etc/kubernetes/pki/etcd/ca.crt --cert /etc/kubernetes/pki/etcd/peer.crt --key /etc/kubernetes/pki/etcd/peer.key member list

take note on the etcd-member-id of the node you removed (eg. "3cce9d6104afe4be")

Step 5: Remove etcd member

kubectl exe <etcd-pod-name> -n kube-system -- etcdctl --cacert /etc/kubernetes/pki/etcd/ca.crt --cert /etc/kubernetes/pki/etcd/peer.crt --key /etc/kubernetes/pki/etcd/peer.key member remove <etcd-member-id>
⚠️ **GitHub.com Fallback** ⚠️