How to remove all Terminating pods

Sometimes all pods of k8s will be in Terminating state, use this command to clean up all pods.

1
2
3
4
5
kubectl get pods --all-namespaces | grep Terminating | while read line; do
pod_name=$(echo $line | awk '{print $2}' ) \
name_space=$(echo $line | awk '{print $1}' ); \
kubectl delete pods $pod_name -n $name_space --grace-period=0 --force
done

How to remove all Terminating pods
https://blog.justforlxz.com/2023/03/15/How-to-remove-all-Terminating-pods/
作者
小竹
发布于
2023年3月15日
许可协议