k8s

containerd清理不用的镜像

背景

我的master根目录只有40G,发现水位已经达到了76%
file

解决

我同时跑了docker和containerd,先清理docker

docker system prune

file

再删除不用的镜像和退出的容器。

docker images
docker rmi xxx
docker rm $(docker ps -a | grep -i exit | awk '{print $1}'')

下面清理containerd

crictl images | grep none | awk '{print $3} '| xargs crictl rmi

file

这些:的镜像是因为自动构建时的中间镜像或者多次推送新镜像替换了老镜像的tag,原来镜像就变成了:而不会被删除。

清理后水位下降到66%
file

整理一下常用清理集群资源的命令

  1. 清理 Evicted 状态的 Pod
    kubectl get pods --all-namespaces  | grep Evicted
  2. 清理 Error 状态的 Pod
    kubectl get pods --all-namespaces  | grep Error | awk '{print $1,$2}' | xargs -L1 kubectl delete pod -n
  3. 清理 Completed 状态的 Pod
    kubectl get pods --all-namespaces  | grep Completed | awk '{print $1,$2}' | xargs -L1 kubectl delete pod -n
  4. 清理没有被使用的 PV
    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}'
  5. 清理没有被绑定的 PVC
    kubectl get pvc --all-namespaces | grep -v Bound | awk '{print $1,$2}' | xargs -L1 kubectl delete pvc -n
  6. 清理没有被绑定的 PV
    kubectl get pv | tail -n +2 | grep -v Bound | awk '{print $1}' | xargs -L1 kubectl delete pv
  7. 清理含有僵尸进程的pod
    ps -A -ostat,ppid | grep -e '^[Zz]' | awk '{print }' | xargs kill -HUP > /dev/null 2>&1
    ps aux | grep pid
    k delete po xxx -n xxx

    file
    file

分类: k8s
0 0 投票数
文章评分
订阅评论
提醒
guest

0 评论
内联反馈
查看所有评论

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部
0
希望看到您的想法,请您发表评论x