当前位置:网站首页>如何清理废弃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 。
边栏推荐
- Three methods of MySQL backup
- QT official example: QT quick controls - Gallery
- paddlepaddle 28 搭建基于卷积的自动编码机
- iptable端口重定向 MASQUERADE[通俗易懂]
- Uncover the whole link communication process of dewu customer service im
- 微信小程序视频分享平台系统毕业设计毕设(2)小程序功能
- Leetcode(154)——寻找旋转排序数组中的最小值 II
- Wechat nucleic acid detection appointment applet system graduation design completion (5) task statement
- Redis(7)----数据库与过期键
- Night God simulator +fiddler packet capture test app
猜你喜欢

exness深度好文:动性系列-黄金流动性实例分析(五)

Please, stop painting star! This has nothing to do with patriotism!

pycharm 修改 pep8 E501 line too long > 0 characters

Wechat nucleic acid detection appointment applet system graduation design completion (1) development outline

Wechat applet video sharing platform system graduation design completion (7) Interim inspection report

Esp32-c3 introductory tutorial question ⑩ - error: implicit declaration of function 'ESP_ blufi_ close‘;

300+篇文献!一文详解基于Transformer的多模态学习最新进展

微信小程序视频分享平台系统毕业设计毕设(6)开题答辩PPT

Leetcode(81)——搜索旋转排序数组 II

Another double non reform exam 408, will it be cold? Software College of Nanchang Aviation University
随机推荐
Simulateur nightGod + application de test de capture de paquets Fiddler
Summary of fun free GM games
RDK仿真实验
夜神模拟器+Fiddler抓包测试App
Wechat nucleic acid detection appointment applet system graduation design completion (5) task statement
2020 Internet industry terminology
Leetcode interview question 16.15 Abacus wonderful calculation
C# 检测图片是否被旋转并修改到正真的旋转
Installation tutorial and simple call of Matplotlib
Chrome 正式支持 MathML,默认在 Chromium Dev 105 中启用
拿起相机,便是最好的艺术疗愈
Rte11 interrupt decoupling function
QQmlApplicationEngine
Aptos教程-参与官方激励测试网(AIT2 激励测试网)
面试,关于线程池的那些事
Ue4 dessine un cercle avec une ligne de contour
Leetcode 面试题 16.15. 珠玑妙算
Wechat nucleic acid detection appointment applet system graduation design (2) applet function
Three methods of MySQL backup
微信核酸检测预约小程序系统毕业设计毕设(1)开发概要
