当前位置:网站首页>How to clean up discarded PVs and their corresponding folders
How to clean up discarded PVs and their corresponding folders
2022-07-02 18:44:00 【Migrant worker Lao Wang】
Blog home page :https://tomcat.blog.csdn.net
Blogger's nickname : Lao Wang of migrant workers
Main areas :Java、Linux、K8S
We look forward to your attention, praise and collection comments
Catalog
pv yes k8s Important storage resources in . Since it's storage , That involves taking up disk space . In the use of k8s In the process of clustering , If you don't pay attention to cleaning and discarding pv, Then it's easy to accumulate a lot of garbage pv, Not only is it inconvenient k8s Management of , It may also lead to insufficient disk space .
This article is written by storage class Dynamically supplied pv For example , Demo obsolete pv and nfs Clean up the corresponding folder on the server .
If the pv I'm not familiar with the recycling strategy , Can browse k8s in pv Recycling strategy for This article ( The title of the article on the left contains hyperlinks , You can directly click to jump ).
1 Confirm the status before cleaning
Confirm current k8s Clustered pv Number .
Confirm current nfs The number of files under the shared path of the server .
Confirm current nfs Disk usage of the server .
2 Export obsolete pv stay nfs The corresponding path on the server
kubectl get pv \
-o custom-columns=STATUS:.status.phase,PATH:.spec.nfs.path \
|grep Released \
|awk '{print $2}' \
> 156.txt
there 156.txt Text for storing path information , Because of the master Node's intranet IP by 192.168.130.156, So it's called 156.txt, In their own cleaning process , You can name this file as you like .
Exported text :
/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 clear k8s The abandonment of pv
Write the following code to the computer , And run , You can clean it up 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
As shown in the figure below , After running the script ,Released State of pv Have been deleted ,pv Quantity from 583 Down to 38.


4 clear nfs Obsolete files on the server
Will be the first 2 The text file generated in step and the following code are written nfs The server , And run ${ Script path } ${ Text path }, Such as ./cleaner.sh 156.txt, That is, you can clean up waste files .
#!/bin/bash
whiteList=`cat $1`
echo "${whiteList}" | while read line
do
rm -rf "$line"
done
The results are shown in the following figure , Cleaned up 500 Multiple folders , and 60 many G Of disk space .

If you want to reprint , Please indicate the source of this article : Migrant worker Lao Wang's CSDN Blog https://blog.csdn.net/monarch91 .
边栏推荐
猜你喜欢

Leetcode 面试题 16.17. 连续数列

Leetcode interview question 17.01 Addition without plus sign

Détends - toi encore! Ces nouveaux étudiants peuvent s'installer directement à Shanghai

【每日一题】第一天
![Unity学习shader笔记[八十二]增强单通道颜色渲染的黑白处理](/img/db/d745a434e76511742d1264706b5d9a.png)
Unity学习shader笔记[八十二]增强单通道颜色渲染的黑白处理

Wechat applet video sharing platform system graduation design (2) applet function

Wechat applet video sharing platform system graduation design completion (6) opening defense ppt

Redis(7)----数据库与过期键

M2DGR:多源多场景 地面机器人SLAM数据集(ICRA 2022 )

Pit encountered during installation of laravel frame
随机推荐
问题包含哪些环节
Relax again! These fresh students can settle directly in Shanghai
SteamOS 3.3 Beta 发布,Steam Deck 中文键盘终于来了
How to write controller layer code gracefully?
Please, stop painting star! This has nothing to do with patriotism!
Server PHP environment building tutorial, PHP server environment building graphic explanation
【西北工业大学】考研初试复试资料分享
Wechat nucleic acid detection appointment applet system graduation design completion (1) development outline
科技公司不同人对Bug的反应 | 每日趣闻
The difference between promise and observable
RTE11- 中断解耦功能
[Yugong series] July 2022 go teaching course 001 introduction to go language premise
Redis(6)----对象与数据结构
Implementation shadow introduction
[Oracle final review] addition, deletion and modification of tablespaces, tables, constraints, indexes and views
Leetcode 面试题 16.17. 连续数列
MySQL about only_ full_ group_ By limit
Leetcode 面试题 16.11. 跳水板
@Component cannot get Dao layer
Nm01 function overview and API definition of nm module independent of bus protocol
