Last active
April 13, 2023 06:05
-
-
Save zulhfreelancer/a5c2f2cb36146b793c82e5b1167ca90e to your computer and use it in GitHub Desktop.
How to delete all evicted pods from all namespaces?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is for Mac OSX users. If you are on Linux, replace 'gxargs' with 'xargs'. | |
# To install 'gxargs' command using Homebrew, run 'brew install findutils' first. | |
# Without parallel (ideal for small number of pods) | |
kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace=" $1}' | gxargs -n 1 -d '\n' bash -c 'kubectl delete pod $0 $1' | |
# With parallel (ideal for big number of pods) | |
# To install 'parallel' command using Homebrew, run 'brew install parallel' first. | |
# To install 'parallel' command on Linux (e.g. Ubuntu), refer https://askubuntu.com/a/298598/972977 for instructions. | |
kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace=" $1}' | gxargs -n 1 -d '\n' bash -c 'echo kubectl delete pod $0 $1' | parallel | |
# References: | |
# - https://superuser.com/a/467284 | |
# - https://gist.github.com/svx/a2310feb53fb71ad232bd7f66fada5bc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment