-
-
Save superseb/2cf186726807a012af59a027cb41270d to your computer and use it in GitHub Desktop.
#!/bin/sh | |
# OUTDATED: please refer to the link below for the latest version: | |
# https://github.com/rancherlabs/support-tools/blob/master/extended-rancher-2-cleanup/extended-cleanup-rancher2.sh | |
docker rm -f $(docker ps -qa) | |
docker volume rm $(docker volume ls -q) | |
cleanupdirs="/var/lib/etcd /etc/kubernetes /etc/cni /opt/cni /var/lib/cni /var/run/calico /opt/rke" | |
for dir in $cleanupdirs; do | |
echo "Removing $dir" | |
rm -rf $dir | |
done |
this repo is a hidden gem
Is this command rm all container in docker (event it doesn't relate, and installed before Rancher cluster)?
Is this command rm all container in docker (event it doesn't relate, and installed before Rancher cluster)?
It will remove all running container on your machine (even it's not related to Rancher cluster)
I've changed the script to just remove rancher / k8s containers and images and use docker volume prune to cleanup volumes:
#!/bin/bash
user=$EUID
if [ "${user}" != "0" ]; then
echo
echo "$0 must be run as root - you are running as $EUID"
echo
exit 1
fi
echo
echo "About to destroy Rancher 2.x install"
echo "5s to cancel with ^c"
echo
sleep 5
containers=$(docker ps -a | grep -E "rancher|k8s" | awk '{print $1}')
if [ "${containers}x" != "x" ]
then
docker rm -f $containers
else
echo "No containers - ignoring docker rm"
fi
images=$(docker images -a | grep -E "rancher|k8s" | awk '{print $3}')
if [ "${images}x" != "x" ]
then
docker rmi $images
else
echo "No images - ignoring docker rmi"
fi
docker volume prune
cleanupdirs="/var/lib/etcd /etc/kubernetes /etc/cni /opt/cni /var/lib/cni /var/run/calico /opt/rke"
for dir in $cleanupdirs; do
echo "Removing $dir"
rm -rf $dir
done
When installing rancher-agent on the same host for testing purposes the cluster would not run properly until I also removed all data from /opt/rancher
, perhaps it was only one of the three dirs:
root@rancher:~# ls /opt/rancher
certs-cache k3s management-state
Thanks !
ros should have a clean function. Or reinstall from cloud-config...
Will this unregister the node from the cluster too ?
saved me a bunch of time, tyvm!
Are you shure it's /var/run/calico
and not /var/lib/calico
?
@HoffmannP This gist is outdated, I updated the code with a link to the updated version.
awesome work!