Skip to content

Instantly share code, notes, and snippets.

@ragaar
Last active June 21, 2019 17:55
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 ragaar/d36ce69de534ae58f64a317e09bae440 to your computer and use it in GitHub Desktop.
Save ragaar/d36ce69de534ae58f64a317e09bae440 to your computer and use it in GitHub Desktop.
Cleanup script for Rancher v2.x
#!/bin/sh
containers=$(docker ps -qa)
for container in $containers; do
echo "Removing $container"
done
if [ ! -z "$containers" ]
then
docker rm -f $containers
fi
volumes=$(docker volume ls -q)
for volume in $volumes; do
echo "Removing $volume"
done
if [ ! -z "$volumes" ]
then
docker volume rm $volumes
fi
for mount in $(mount | grep tmpfs | grep '/var/lib/kubelet' | awk '{ print $3 }') /var/lib/kubelet; do
if [ -d $mount ]
then
umount $mount;
fi
done
cleanupdirs="/etc/ceph /etc/cni /etc/kubernetes /opt/cni /opt/rke /run/secrets/kubernetes.io /run/calico /run/flannel /var/lib/calico /var/lib/etcd /var/lib/cni /var/lib/kubelet /var/lib/rancher/rke/log $
for dir in $cleanupdirs; do
if [ -d $dir ]
then
echo "Removing $dir"
rm -rf $dir
fi
done
@ragaar
Copy link
Author

ragaar commented Jun 20, 2019

curl -L https://gist.githubusercontent.com/ragaar/d36ce69de534ae58f64a317e09bae440/raw/e4a0939878685539a9b11f259f3cba95ffd3fbfe/cleanup.sh -o cleanup.sh
chmod a+x cleanup.sh
sudo sh cleanup.sh

sudo permissions could, most likely, be restricted to the umount and rm -rf, but it depends on your locally defined permissions.

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