“探路者”亚马逊云科技 如何探路云计算?
51CTO社区编辑加盟指南,欢迎关注!
长时间运行的集群,常会面临各种资源耗尽的问题,另外磁盘不足时 Kubelet 还会主动清理镜像增加不确定因素,本文提供了一些命令片段用于清理工作。
1. Kubernetes 基础对象清理 清理 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 get pods --all-namespaces -o wide | grep Completed | awk '{print $1,$2}' | xargs -L1 kubectl delete pod -n 清理没有被使用的 PV kubectl describe -A pvc | grep -E "^Name:.*$|^Namespace:.*$|^Used By:.*$" | grep -B 2 "" | grep -E "^Name:.*$|^Namespace:.*$" | cut -f2 -d: | paste -d " " - - | xargs -n2 bash -c 'kubectl -n ${1} delete pvc ${0}' 清理没有被绑定的 PVC 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 2. Linux 清理 查看磁盘全部空间 Filesystem Size Used Avail Use% Mounted on /dev/sda2 100G 47G 54G 47% / 查看指定目录占用 du -sh . 24G . 删除指定前缀的文件夹 cd /nfsdata ls | grep archived- |xargs -L1 rm -r 清理僵尸进程 ps -A -ostat,ppid | grep -e '^[Zz]' | awk '{print }' | xargs kill -HUP > /dev/null 2>&1 3. Docker 清理 查看磁盘使用情况 docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 361 23 178.5GB 173.8GB (97%) Containers 29 9 6.682GB 6.212GB (92%) Local Volumes 4 0 3.139MB 3.139MB (100%) Build Cache 0 0 0B 0B 清理 none 镜像 docker images | grep none | awk '{print $3}' | xargs docker rmi 清理不再使用的数据卷 docker volume rm $(docker volume ls -q)
或者
docker volume prune 清理缓存 docker builder prune 全面清理
删除关闭的容器、无用的存储卷、无用的网络、dangling 镜像(无 tag 镜像)
docker system prune -f 清理正则匹配上的镜像
这里清理的是 master-8bcf8d7-20211206-111155163 格式的镜像。
docker images |grep -E "([0-9a-z]*[-]){3,}[0-9]{9}" |awk '{print $3}' | xargs docker rmi 4. 设置定时 查看定时任务 crontab -l 设置定时任务 crontab -e
文本新增定时任务
*/35 */6 * * * docker images | grep none | awk '{print $3}' | xargs docker rmi 45 1 * * * docker system prune -f
这里第一个任务是每隔六个小时的第 35 分钟执行,第二个任务每天的 1 时 45 分执行。
定时任务的格式
设置定时格式: * * * * * shell
第一个星号,minute,分钟,值为 0-59 第二个星号,hour,小时,值从 0-23 第三个星号,day,天,值为从 1-31 第四个星号,month,月,值为从 1-12 月,或者简写的英文,比如 Nov、Feb 等 第五个星号,week 周,值为从 0-6 或者简写的英文,Wen、Tur 等,代表周几,其中 0 代表周末
相关文章
如果说有一个明显的预测在这原本不可预测的一年里得到了证实,那就是云计算应用的加速。只要看看每一个主要的云持续着非常健康的两位数增长率。对于企业来说,这是为了适应虚拟环境和突然被封锁的世界中受限的供应链2026-11-29
云梦级2月14日云梦级消息,据澎湃新闻报道,近日,DeepSeek 网页/ APP 正在测试新的长文本模型结构,支持 1M 上下文。其API 服务不变,仍为 V3.2,仅支持 128K 上下文。 这也2026-11-29
新浪科技讯 北京时间4月6日早间消息,据报道,谷歌母公司Alphabet计划在未来几周停用甲骨文的财务软件,转而使用SAP的同类产品。 谷歌通过电子邮件对员工表示,Alphabet和谷歌的核心财务系统2026-11-29
Anthropic证实:Claude Opus 4.1和Opus 4模型出现 “降智” 现象,已紧急修复!
Anthropic 公司发布了一份事件报告,确认其最新的 Claude Opus4.1和 Opus4模型在8月25日至28日之间的确遭遇了 “降智” 现象。用户们在使用这些模型时,可能会发现回答质量显2026-11-29
云梦级2月26日云梦级消息,据京东黑板报透露,为进一步提升 “又好又便宜” 的消费体验,满足用户对日用快消品实在好价、简单优惠、正品保障的消费需求,京东APP正式上线“百亿超市”频道,加大百亿补贴对商2026-11-29
云梦级3月31日云梦级消息,3月31日,如祺出行发布截至2025年度全年业绩公告。报告期内,如祺出行核心财务指标全面向好,除录得总收入52.86亿元,同比大增114.6%,年内订单量、交易额均录得翻倍2026-11-29

最新评论