Files
shell-scripts/0-部署应用/Oracle-Cloud/k3s集群/9-完全清理k3s集群.sh
2024-11-28 16:42:36 +08:00

63 lines
1.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
echo "开始执行k3s默认的清除内容"
chmod +x /usr/local/bin/k3s-uninstall.sh
chmod +x /usr/local/bin/k3s-agent-uninstall.sh
/usr/local/bin/k3s-uninstall.sh
/usr/local/bin/k3s-agent-uninstall.sh
rm -rf /root/k3s-install/
echo "开始清理containerd"
echo "关停所有的容器!"
crictl ps -a | grep -v Running | awk '{print $1}' | xargs sudo crictl rm && crictl rmi --prune
echo "清除所有的镜像!"
crictl images -q | xargs -n 1 crictl rmi 2>/dev/null
apt-remove containerd
echo "开始清理docker相关的内容"
docker system df
# 占用存储空间,又没有用的容器
docker images -aq -f 'dangling=true' | xargs docker rmi
# 删除所有
echo "删除所有"
docker system prune -a
echo ""
echo "清除docker运行的容器"
docker stop $(docker ps -a | awk '{print $1 }')
docker rm $(docker ps -a | awk '{print $1 }')
echo "删除镜像"
docker rmi $(docker images | grep "none" | awk '{print $3}')
echo "删除所有镜像 谨慎使用"
docker rmi $(docker images -q) -f
echo ""
echo "开始删除docker的文件"
rm -rf /var/lib/docker
echo " "
echo "开始清理系统残余"
echo ""
apt-get autoremove
echo "开始清理系统日志残留"
rm -rf /var/log/journal/