At times a node may need to be cleaned of all state to ensure it is consistent for further use in a cluster. This article and script are for Rancher 2.x.
Please note, this script will delete all containers, volumes, images, network interfaces, and directories that relate to Rancher and Kubernetes. It can also optionally flush all iptables rules. It is important to perform pre-checks, and backup the node as needed before proceeding with any steps below.
- A node that needs cleaning, it should no longer be a member of any cluster.
- A copy of the cleanup script, and root/sudo access.
- Check the running containers or Pods, these will be forcefully deleted in the following steps.
- Confirm you are on the correct node and are ready to proceed with cleaning all state.
The below steps use a script to automate the clean of a node, the commands used can be run manually as needed, follow the steps below for an automated approach to cleaning a node.
- Login to the node, download the cleanup script:
curl -sLO https://github.com/rancherlabs/support-tools/raw/master/extended-rancher-2-cleanup/extended-cleanup-rancher2.sh
You should now have a copy of the script in the current directory.
- Run the script:
sudo bash extended-cleanup-rancher2.sh
If desired, add a
flush argument to also flush iptables rules.
sudo bash extended-cleanup-rancher2.sh flush
- Restart the node
The node is now in a clean consistent state to be reused in a cluster.