Short and sweet for this one. I had a failing cron job in Kubernetes which had run several times overnight.
I wanted to delete many instances of errored pods, without having to resort to using a manual delete pod
command.
watch kubectl get pods -n some-namespace
NAME READY STATUS RESTARTS AGE
my-broken-pod-28818371-5nppx 0/1 Error 0 13h
my-broken-pod-28818371-6jr5w 0/1 Error 0 13h
my-broken-pod-28818371-7qfn7 0/1 Error 0 13h
my-broken-pod-28818371-cmgtf 0/1 Error 0 13h
my-broken-pod-28818371-jkmpl 0/1 Error 0 13h
my-broken-pod-28818371-l8kvs 0/1 Error 0 13h
my-broken-pod-28818371-tfkdt 0/1 Error 0 13h
my-broken-pod-28818731-484c5 0/1 Error 0 7h34m
my-broken-pod-28818731-7685t 0/1 Error 0 7h38m
my-broken-pod-28818731-7qgfd 0/1 Error 0 7h40m
my-broken-pod-28818731-djjl5 0/1 Error 0 7h29m
my-broken-pod-28818731-f6khl 0/1 Error 0 7h39m
my-broken-pod-28818731-fqjvt 0/1 Error 0 7h39m
my-broken-pod-28818731-ssp56 0/1 Error 0 7h37m
my-broken-pod-28819091-5tn78 0/1 Error 0 89m
my-broken-pod-28819091-b77lx 0/1 Error 0 99m
my-broken-pod-28819091-cdx78 0/1 Error 0 100m
my-broken-pod-28819091-jft9n 0/1 Error 0 98m
my-broken-pod-28819091-mkwl5 0/1 Error 0 99m
my-broken-pod-28819091-ndwnc 0/1 Error 0 94m
my-broken-pod-28819091-vdvdw 0/1 Error 0 97m
Code language: JavaScript (javascript)
And the command to remove:
kubectl delete pod -n some-namespace --field-selector=status.phase=Failed
Code language: JavaScript (javascript)
After which they should all be terminated.
Excellent.