Skip to content

Instantly share code, notes, and snippets.

@Jivvon
Forked from JhoLee/reset-k8s-node.sh
Created February 17, 2022 06:32
Show Gist options
  • Save Jivvon/f74487972b0f84cf58921a3529c9a025 to your computer and use it in GitHub Desktop.
Save Jivvon/f74487972b0f84cf58921a3529c9a025 to your computer and use it in GitHub Desktop.
Reset K8S Node
echo -n "Really want to reset this node? (y/N): "
read -r check
if [[ "$check" = "y" ]]; then
echo "[INFO] Reset kubeadm"
kubeadm reset -f
echo "[INFO] Stop kubelet & docker service"
systemctl stop kubelet docker docker.socket
echo "[INFO] Remove K8S files"
rm -rvf /etc/kubernetes/*
rm -rvf /var/lib/kubelet/*
rm -rvf /var/lib/etcd/
echo "[INFO] Remove K8S network files"
rm -rf /var/run/calico/ /var/lib/calico/ /etc/cni/ /var/lib/cni/
ifconfig cni0 down
ifconfig flannel.1 down
ifconfig tunl0 down
ip link delete cni0
ip link delete flannel.1
ip link delete tunl0
echo "[INFO] Restart docker"
systemctl restart docker
echo "[INFO] Done. You have to delete the node from your k8s with 'kubectl delete node $(hostname)'"
else
echo "[INFO] Cancel."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment