Skip to content

Instantly share code, notes, and snippets.

@jholt456
Forked from superseb/cleanup.sh
Last active January 21, 2021 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jholt456/f0ff07bf942d78bad033b5c378f28146 to your computer and use it in GitHub Desktop.
Save jholt456/f0ff07bf942d78bad033b5c378f28146 to your computer and use it in GitHub Desktop.
Cleanup host added as custom to Rancher 2.0
#!/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
echo
echo "About to clean ip tables"
echo "5s to cancel with ^c"
echo
sleep 5
echo
echo "Cleaning ip tables"
echo
iptables -F -t nat
iptables -X -t nat
iptables -F -t mangle
iptables -X -t mangle
iptables -F
iptables -X
echo
echo "Restarting Docker"
echo
service docker restart
@jholt456
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment