How to list Kubernetes recently deleted pods?

as far as i know you may not get the pod details once the pod is deleted. can i know what is the usecase?

example:

  1. if a pod created using - kubectl run busybox-test-pod-status --image=busybox --restart=Never -- /bin/false you will have a pod with status termiated:error
  2. if a pod is created using - kubectl run busybox-test-pod-status --image=busybox --restart=Never -- /bin/true you will have pod with status terminated:Complted
  3. if container in a pods restarts: the pod will be alive and you can get the logs of previous container (only the previous container) using kubectl logs --container < container_name > --previous=true < pod_name >
  4. if you doing an upgrade of you app and you are creating pods using deployments. if the update deployment "say a new image". pod will be terminated and new pod will be created. you can get the pod details from depoyment yaml. if you want to get details of previous pod you have see "spec" section of previous deployment yaml

As of today, kubectl get pods -a is deprecated, and as a result you cannot get deleted pods.

What you can do though, is to get a list of recently deleted pod names - up to 1 hour in the past unless you changed the ttl for kubernetes events - by running:

kubectl get event -o custom-columns=NAME:.metadata.name | cut -d "." -f1

You can then investigate further issues within your logging pipeline if you have one in place.

Tags:

Kubernetes