Created
July 5, 2023 08:52
-
-
Save leonsteinhaeuser/524dd03e6c74229dd0dc658e569c06fc to your computer and use it in GitHub Desktop.
Force delete all "Terminating" pods in Kubernetes (not namespace aware)
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 | |
# identify kubernetes config file | |
k_config_path=~/.kube/config | |
if [ "$KUBE_CONFIG" != "" ]; then | |
k_config_path=$KUBE_CONFIG | |
fi | |
# identify kubernetes context | |
k_context="" | |
if [ "$KUBE_CONTEXT" != "" ]; then | |
k_context=$KUBE_CONTEXT | |
fi | |
# identify pods to force delete and prepare command | |
terminating_pods=$(kubectl --kubeconfig $k_config_path --context $k_context get pods -A | grep Terminating | awk '{print "-n " $1 " delete pods " $2 " --force --grace-period 0"}') | |
# execute command | |
while read -r line; do | |
kubectl --kubeconfig $k_config_path --context $k_context $line | |
done <<< "$terminating_pods" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The variables 'KUBE_CONFIG' and 'KUBE_CONTEXT' must be set if you want to change the default settings.