当前位置:网站首页>Common commands for cleaning up kubernetes cluster resources
Common commands for cleaning up kubernetes cluster resources
2022-06-23 21:34:00 【Chenshaowen】
Long running clusters , We often face the problem of exhaustion of various resources , In addition, when the disk is insufficient Kubelet It also actively cleans up the image, increasing uncertainty , This article provides some command snippets for cleaning up .
1. Kubernetes Base object cleanup
- clear Evicted State of Pod
1 | kubectl get pods --all-namespaces -o wide | grep Evicted | awk '{print $1,$2}' | xargs -L1 kubectl delete pod -n |
|---|
- clear Error State of Pod
1 | kubectl get pods --all-namespaces -o wide | grep Error | awk '{print $1,$2}' | xargs -L1 kubectl delete pod -n |
|---|
- clear Completed State of Pod
1 | kubectl get pods --all-namespaces -o wide | grep Completed | awk '{print $1,$2}' | xargs -L1 kubectl delete pod -n |
|---|
- Clean up unused PV
1 | kubectl describe -A pvc | grep -E "^Name:.*$|^Namespace:.*$|^Used By:.*$" | grep -B 2 "<none>" | grep -E "^Name:.*$|^Namespace:.*$" | cut -f2 -d: | paste -d " " - - | xargs -n2 bash -c 'kubectl -n ${1} delete pvc ${0}' |
|---|
- Clean up unbound PVC
1 | kubectl get pvc --all-namespaces | tail -n +2 | grep -v Bound | awk '{print $1,$2}' | xargs -L1 kubectl delete pvc -n |
|---|
- Clean up unbound PV
1 | kubectl get pv | tail -n +2 | grep -v Bound | awk '{print $1}' | xargs -L1 kubectl delete pv |
|---|
2. Linux clear
- View all disk space
1 2 3 4 | df -hl / Filesystem Size Used Avail Use% Mounted on /dev/sda2 100G 47G 54G 47% / |
|---|
- View the occupation of the specified directory
1 2 3 | du -sh . 24G . |
|---|
- Delete the folder with the specified prefix
1 2 | cd /nfsdata ls | grep archived- |xargs -L1 rm -r |
|---|
- Clean up the zombie process
1 | ps -A -ostat,ppid | grep -e '^[Zz]' | awk '{print }' | xargs kill -HUP > /dev/null 2>&1 |
|---|
3. Docker clear
- Check disk usage
1 2 3 4 5 6 7 | 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 |
|---|
- clear none Mirror image
1 | docker images | grep none | awk '{print $3}' | xargs docker rmi |
|---|
- Clean up data volumes that are no longer in use
1 | docker volume rm $(docker volume ls -q) |
|---|
perhaps
1 | docker volume prune |
|---|
- Clean cache
1 | docker builder prune |
|---|
- Comprehensive cleaning
Delete closed containers 、 Useless storage volumes 、 Useless network 、dangling Mirror image ( nothing tag Mirror image )
1 | docker system prune -f |
|---|
- Clean up images on regular matches
What's cleared here is master-8bcf8d7-20211206-111155163 Image of format .
1 | docker images |grep -E "([0-9a-z]*[-]){3,}[0-9]{9}" |awk '{print $3}' | xargs docker rmi |
|---|
4. Set the timing
- View scheduled tasks
1 | crontab -l |
|---|
- Set timing task
1 | crontab -e |
|---|
Text add scheduled task
1 2 | */35 */6 * * * docker images | grep none | awk '{print $3}' | xargs docker rmi 45 1 * * * docker system prune -f |
|---|
The first task here is... Every six hours 35 Minute execution , The second task is... Every day 1 when 45 Points to perform .
- Format of scheduled tasks
Set timing format : * * * * * shell
The first asterisk ,minute, minute , The value is 0-59 The second asterisk ,hour, Hours , Value from 0-23 The third asterisk ,day, God , Value from 1-31 The fourth asterisk ,month, month , Value from 1-12 month , Or abbreviated English , such as Nov、Feb etc. The fifth asterisk ,week Zhou , Value from 0-6 Or abbreviated English ,Wen、Tur etc. , Represents the day of the week , among 0 On behalf of the weekend
https://www.chenshaowen.com/blog/common-commands-for-cleaning-up-kubernetes-cluster-resources.html
边栏推荐
- JS namespace
- Who do you want to open a stock account? Is it safe to open an account online?
- Prometheus primary body test
- Full text search of MySQL
- Do you really understand the cache penetration, cache breakdown and cache avalanche in rotten street?
- Go language core 36 lectures (go language practice and application 27) -- learning notes
- 【Debian】Debian使用笔记
- . Net Core 3. X MVC built-in log extension log4net
- The printed picture is dark. It will make you clear in seconds
- Copilot - employee, your layoff notice has been delivered
猜你喜欢

How does PMO select and train project managers?

Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis
![Harmonyos application development -- mynotepad[memo][api v6] based on textfield and image pseudo rich text](/img/b1/71cc36c45102bdb9c06e099eb42267.jpg)
Harmonyos application development -- mynotepad[memo][api v6] based on textfield and image pseudo rich text

Facing the problem of lock waiting, how to realize the second level positioning and analysis of data warehouse

蓝牙芯片|瑞萨和TI推出新蓝牙芯片,试试伦茨科技ST17H65蓝牙BLE5.2芯片

New SQL syntax quick manual!
Application of JDBC in performance test

How to gradually improve PMO's own ability and management level

Gradle asked seven times. You should know that~

Four aspects of PMO Department value assessment
随机推荐
【TypeScript】在实战中的一些总结
Cloud database smooth disassembly scheme
Supplementary usage of upload component in fusiondesign 1
[5 minutes to play lighthouse] quickly use Chang'an chain
What if there are too few jetpack compose theme colors? Design your own color system
【5分钟玩转Lighthouse】快速使用长安链
Wechat smart operation 3.0+ Alipay digital transformation 3.0
Full text search of MySQL
New SQL syntax quick manual!
I am 30 years old, no longer young, and have nothing
How to make a label for an electric fan
What about the cloud disk service status error? How to format the cloud disk service?
Processing of purchase return in SAP mm preliminary transaction code Migo
Thinking about distributed system consensus
[typescript] some summaries in actual combat
Global and Chinese market of American football catch gloves 2022-2028: Research Report on technology, participants, trends, market size and share
How PMO uses two dimensions for performance appraisal
I'm in Shenzhen. Where can I open an account? Is online account opening safe?
How to convert []byte to io. in go Reader?
Where should DNS start? I -- from the failure of Facebook