-
-
Save jholt456/f0ff07bf942d78bad033b5c378f28146 to your computer and use it in GitHub Desktop.
Cleanup host added as custom to Rancher 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run:
curl https://gist.githubusercontent.com/jholt456/f0ff07bf942d78bad033b5c378f28146/raw/cc9edb0f1395fee190ed4bf6437a6ca2652d4ed6/cleanup.sh > ./clean-rke.sh && chmod a+x ./clean-rke.sh && sudo ./clean-rke.sh