How to clean a Rancher 2.x node

Table of Contents


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

You should now have a copy of the script in the current directory.

  • Run the script:

sudo bash

If desired, add a flush argument to also flush iptables rules.

sudo bash flush

  • Restart the node

The node is now in a clean consistent state to be reused in a cluster.

Was this article helpful?
3 out of 3 found this helpful



Please sign in to leave a comment.