How to delete multiple Kubernetes pods having the same name expression except the latest one?

8/29/2019

I have multiple pods running as below. I want to delete them all except the one having minimum age. How to do it?

enter image description here

-- Vatan Soni
kubernetes
kubernetes-pod

1 Answer

8/29/2019

Something like this? Perhaps also add -l app=value to filter for a specific app

kubectl get pods --sort-by=.metadata.creationTimestamp -o name | head -n -1 | xargs echo kubectl delete

(Remove echo to do it for realz)

-- Janos Lenart
Source: StackOverflow