当前位置:网站首页>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 .
边栏推荐
- @Component 拿不到dao层
- Wechat applet video sharing platform system graduation design completion (5) assignment
- How to set vscode to delete the whole line shortcut key?
- Summary of fun free GM games
- exness深度好文:动性系列-黄金流动性实例分析(五)
- 元宇宙链游系统开发(逻辑开发)丨链游系统开发(详细分析)
- Meta universe chain game system development (logic development) - chain game system development (detailed analysis)
- Concepts and differences of PR curve and ROC curve
- 【每日一题】第一天
- Leetcode interview question 17.04 Vanishing numbers
猜你喜欢

Wechat applet video sharing platform system graduation design completion (4) opening report

QT official example: QT quick controls - Gallery

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

Another double non reform exam 408, will it be cold? Software College of Nanchang Aviation University

夜神模擬器+Fiddler抓包測試App

A simple PHP personal card issuing program v4.0

Relax again! These fresh students can settle directly in Shanghai

Uncover the whole link communication process of dewu customer service im
![[Northwestern Polytechnic University] information sharing of the first and second postgraduate examinations](/img/15/298ea6f7367741e1e085007c498e51.jpg)
[Northwestern Polytechnic University] information sharing of the first and second postgraduate examinations

学生抖音宣传母校被吐槽“招生减章”,网友:哈哈哈哈哈哈
随机推荐
材质UV遮罩的技巧
A good programmer is worth five ordinary programmers!
产品经理应具备的能力
Unity学习shader笔记[八十二]增强单通道颜色渲染的黑白处理
Another double non reform exam 408, will it be cold? Software College of Nanchang Aviation University
ESP32-C3入门教程 问题篇⑪——esp-tls: create_ssl_handle failed, tls_io_instance->options.trusted_certs null
The text editor hopes to mark the wrong sentences in red, and the text editor uses markdown
【每日一题】第一天
学生抖音宣传母校被吐槽“招生减章”,网友:哈哈哈哈哈哈
sql训练2
Leetcode interview question 16.15 Abacus wonderful calculation
揭秘得物客服IM全链路通信过程
promise 和 Observable 的区别
The difference between promise and observable
【西北工业大学】考研初试复试资料分享
CDN acceleration and breaking J anti-theft chain function
paddlepaddle 28 搭建基于卷积的自动编码机
故障排查:kubectl报错ValidationError: unknown field \u00a0
cJSON 使用详解
C语言中函数参数传递的三种方式
