Last active
June 21, 2019 17:55
-
-
Save ragaar/d36ce69de534ae58f64a317e09bae440 to your computer and use it in GitHub Desktop.
Cleanup script for Rancher v2.x
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/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sudo
permissions could, most likely, be restricted to theumount
andrm -rf
, but it depends on your locally defined permissions.