Reputation: 167
I have tried below command. but this command gets all the pods which are not running for some reason any other way to do this
kubectl delete pods -A --field-selector=status.phase!=Running
Upvotes: 1
Views: 4419
Reputation: 1
To delete all running pods in the current namespace, use the below command
kubectl get pods --field-selector 'status.phase=Failed' | awk '{if ($3 != "Running") system ("kubectl delete pods " $1 )}'
Upvotes: 0
Reputation: 69
You can use the below command for check the init pod with namespace like default-user and delete those pods.
kubectl get pods -A | grep default-user | grep -i "init:" | awk '{if ($4 != "Running") system ("kubectl -n " $1 " delete pods " $2 )}'
Upvotes: 0
Reputation: 12059
This might be what you are looking for, but uses awk and unix output piping.
kubectl get pods --field-selector 'status.phase=Failed' --all-namespaces | awk '{if ($4 != "Running") system ("kubectl -n " $1 " delete pods " $2 )}'
Upvotes: 3