当前位置:网站首页>如何清理废弃pv和其对应的文件夹
如何清理废弃pv和其对应的文件夹
2022-07-02 17:07:00 【农民工老王】
博客主页:https://tomcat.blog.csdn.net
博主昵称:农民工老王
主要领域:Java、Linux、K8S
期待大家的关注点赞收藏留言
pv是k8s中重要的重要的存储资源。既然是存储,那就涉及占用磁盘空间。在使用k8s集群的过程中,如果不注意清理废弃pv,那么就很容易积累大量垃圾pv,不仅不方便k8s的管理,还可能导致磁盘空间不足。
本文以由storage class动态供应的pv为例,演示废弃pv和nfs服务器上对应文件夹的清理。
如果对pv的回收策略不太熟悉,可以浏览 k8s中pv的回收策略 这篇文章(左侧文章标题含有超链接,可以直接点击跳转)。
1 确认清理前状态
确认当前k8s集群的pv数量。
确认当前nfs服务器的共享路径下的文件数量。
确认当前nfs服务器的磁盘占用情况。
2 导出废弃pv在nfs服务器上的对应路径
kubectl get pv \
-o custom-columns=STATUS:.status.phase,PATH:.spec.nfs.path \
|grep Released \
|awk '{print $2}' \
> 156.txt
这里的156.txt为存储路径信息的文本,因本集群的master节点的内网IP为192.168.130.156,因此命名为156.txt,在自己的清理过程中,您可以任意命名这个文件。
导出的文本:
/nfs/k8s/aektemp-data-volume-2-geos-object-store-xa21e-1-pvc-00a765e0-f3f8-4ab8-839f-70e3a89e01a7
/nfs/k8s/gektest-data-volume-geos-relational-store-j7ns8-kerc-0-pvc-0117511b-a121-463b-9115-1877e7bee67a
/nfs/k8s/gek-data-volume-gs-spatiotemporal-index-store-nn2h0-coordinator-0-pvc-01290353-91b1-4640-a8c3-a7f859bcdb72
/nfs/k8s/csh05-data-volume-1-geos-object-store-iamgf-0-pvc-021a966b-04f3-4c50-a852-8462e3af95e7
……
/nfs/k8s/aektemp-data-volume-geos-in-memory-store-xvytd-0-pvc-02fa0401-fdba-4368-800d-43d3b957c2bc
/nfs/k8s/aek-queue-data-volume-arcgis-queue-store-0-pvc-036ffb00-f734-44f7-9a8a-d2028092decc
3 清理k8s中的废弃pv
将下面的代码写入计算机,并运行,即可清理pv。
#!/bin/bash
whiteList=`kubectl get pv |grep Released |awk '{print $1}'`
echo "${whiteList}" | while read line
do
kubectl patch pv ${line} -p '{"spec":{"persistentVolumeReclaimPolicy":"Delete"}}'
done
如下图所示,运行脚本后,Released状态的pv都已经被删除,pv的数量从583下降到38。
4 清理nfs服务器上的废弃文件
将第2步生成的文本文件和下面的代码写入nfs服务器,并运行${脚本路径} ${文本路径}
,如 ./cleaner.sh 156.txt
,即可以清理废弃文件。
#!/bin/bash
whiteList=`cat $1`
echo "${whiteList}" | while read line
do
rm -rf "$line"
done
运行结果如下图所示,清理了500多个文件夹,和60多G的磁盘空间。
如需转载,请注明本文的出处:农民工老王的CSDN博客https://blog.csdn.net/monarch91 。
边栏推荐
- Chrome officially supports MathML, which is enabled in chromium dev 105 by default
- C# 检测图片是否被旋转并修改到正真的旋转
- 昨天阿里学长写了一个责任链模式,竟然出现了无数个bug
- UE4 draw a circle with spline
- Wechat nucleic acid detection appointment applet system graduation design completion (4) opening report
- C语言中函数参数传递的三种方式
- Unity learning shader notes [81] simple color adjustment post-processing (brightness, saturation, contrast)
- Leetcode interview question 16.11 Diving board
- RDK仿真实验
- 国金证券是国企吗?在国金证券开户资金安全吗?
猜你喜欢
Babbitt | metauniverse daily must read: can you buy a virtual anchor for 1000 yuan? Is this the live gospel of small businesses or "cutting leeks"
ESP32-C3入门教程 问题篇⑩——error: implicit declaration of function ‘esp_blufi_close‘;
什么是云原生?这回终于能搞明白了!
Wechat applet video sharing platform system graduation design completion (8) graduation design thesis template
Wechat applet video sharing platform system graduation design completion (7) Interim inspection report
Wechat applet video sharing platform system graduation design completion (6) opening defense ppt
A good programmer is worth five ordinary programmers!
夜神模擬器+Fiddler抓包測試App
微信核酸检测预约小程序系统毕业设计毕设(1)开发概要
Leetcode 面试题 16.11. 跳水板
随机推荐
Qt官方示例:Qt Quick Controls - Gallery
科技公司不同人对Bug的反应 | 每日趣闻
工业软件讲堂-三维CAD设计软件的核心技术解析----讲坛第二次讲座
Leetcode(154)——寻找旋转排序数组中的最小值 II
Iframe nesting details
MySQL 关于 only_full_group_by 限制
ESP32-C3入门教程 问题篇⑩——error: implicit declaration of function ‘esp_blufi_close‘;
Leetcode(81)——搜索旋转排序数组 II
pycharm 修改 pep8 E501 line too long > 0 characters
微信小程序视频分享平台系统毕业设计毕设(2)小程序功能
夜神模擬器+Fiddler抓包測試App
719. Find the distance of the number pair with the smallest K
人人工势场法
QQmlApplicationEngine
cJSON 使用详解
国金证券是国企吗?在国金证券开户资金安全吗?
Renren potential field method
Leetcode interview question 17.01 Addition without plus sign
Ue4 dessine un cercle avec une ligne de contour
Qt官方示例:Qt Quick Controls - Gallery