Skip to content

How to remove all Kubernetes components from nodes

Article Number: 000020162

Environment

RKE1 
RKE2
K3S

Situation

At times a node may need to be cleaned of Kubernetes components for troubleshooting purposes or to reuse the node in another cluster. This article covers the process to remove all Kubernetes components from RKE/RKE2/K3S nodes

Please note, these steps will delete all containers, volumes, CNI network interfaces, and directories that relate to Rancher and Kubernetes. They can also optionally flush all iptables rules and delete container images. It is important to perform pre-checks, and backup the node as needed before proceeding with any steps below.

Prerequisite

  • A node provisioned with the RKE/RKE2/K3S distribution.
  • The node should no longer be a member of the Kubernetes cluster.
  • For RKE1,  the cleanup script is required to be run and it is essential to correctly stop RKE1 services and remove all cluster-related containers, files, and network settings from the node
  • Root/ Sudo access privileges are required to modify system services, directories, and network settings that are part of the cluster's core configuration.
  • Ensure no critical workloads are still running in Kubernetes on the node; these will be forcefully deleted in the following steps.

Resolution

RKE1

The steps below use a script to automate the cleaning of a node; the commands used can be run manually as needed. Follow the steps below to clean a node that has been used previously in a cluster.

  • Log in to the node and 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, the optional -f and -i flags can be used together or individually to flush iptables (-f) and delete container images (-i)

sudo bash extended-cleanup-rancher2.sh -f -i
- Restart the node

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

Please refer to the following documents for similar processes for RKE2/K3S.