DEV Community

Cover image for Clean up k8s/Rancher
Adam K Dean
Adam K Dean

Posted on

Clean up k8s/Rancher

This script is mostly for myself in the future. While playing around with Kubernetes and Rancher, machines become polluted with directories in /var, /etc, and /opt. Pollution is bad. This script will remove those as well as wiping down a system.

Warning: this contains a system prune, and removes everything.

#!/bin/bash
#
# Clean up k8s/rancher
# (Run as root or rm -rf will fail)

docker ps -qa | xargs docker rm -f
docker system prune

cleanupdirs="/var/lib/etcd /etc/kubernetes /etc/cni /opt/cni /var/lib/cni /var/run/calico"
for dir in $cleanupdirs; do
  echo "Removing $dir"
  rm -rf $dir
done
Enter fullscreen mode Exit fullscreen mode

Top comments (0)