-
清理特定状态的 Pod:
-
清理 Evicted 状态的 Pod:
kubectl get pods --all-namespaces -o wide | grep Evicted | awk '{print $1,$2}' | xargs -L1 kubectl delete pod -n
-
清理 Error 状态的 Pod:
kubectl get pods --all-namespaces -o wide | grep Error | awk '{print $1,$2}' | xargs -L1 kubectl delete pod -n
-
清理 Completed 状态的 Pod:
kubectl describe -A pvc | grep -E "^Name:.*$|^Namespace:.*$|^Used By:.*$" | grep -B 2 "<none>" | grep -E "^Name:.*$|^Namespace:.*$" | cut -f2 -d: | paste -d " " - - | xargs -n2 bash -c 'kubectl -n ${1} delete pvc ${0}'
-
-
清理未使用的存储资源:
-
清理没有被使用的 PV(Persistent Volumes):
kubectl describe -A pvc | grep -E "^Name:.*$|^Namespace:.*$|^Used By:.*$" | grep -B 2 "<none>" | grep -E "^Name:.*$|^Namespace:.*$" | cut -f2 -d: | paste -d " " - - | xargs -n2 bash -c 'kubectl -n ${1} delete pvc ${0}'
-
清理没有被绑定的 PVC(Persistent Volume Claims):
kubectl get pvc --all-namespaces | tail -n +2 | grep -v Bound | awk '{print $1,$2}' | xargs -L1 kubectl delete pvc -n
-
清理没有被绑定的 PV:
kubectl get pv | tail -n +2 | grep -v Bound | awk '{print $1}' | xargs -L1 kubectl delete pv
-
-
Linux 系统清理:
-
查看磁盘全部空间:
df -hl /
-
查看指定目录占用:
du -sh .
-
删除指定前缀的文件夹:
ls | grep archived- |xargs -L1 rm -r
-
清理僵尸进程:
ps -A -ostat,ppid | grep -e '^[Zz]' | awk '{print }' | xargs kill -HUP > /dev/null 2>&1
-
-
Docker 清理(如果您的集群使用 Docker 作为容器运行时):
-
查看磁盘使用情况:
docker system df
-
清理 none 镜像:
docker system df
-
清理不再使用的数据卷:
docker volume rm $(docker volume ls -q)或者 docker volume prune
-
清理缓存:
docker builder prune
-
全面清理:
docker system prune -f
-
清理正则匹配上的镜像:
docker images |grep -E "([0-9a-z]*[-]){3,}[0-9]{9}" |awk '{print $3}' | xargs docker rmi
-
Kubernetes 清理资源常用的 Kubernetes 清理命
2025/4/20 5:10:17
来源:https://blog.csdn.net/qq_33192671/article/details/141400017
浏览:
次
关键词:Kubernetes 清理资源常用的 Kubernetes 清理命
版权声明:
本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。
我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com