Get Pods descending sorted from age

#1

Hello I want to call the API to get the latest pods. I have a label filter to get only the specific pod I want to, but the first pod that will shown up is the oldest one. How can I get the youngest one (latest)?

In Short:

How to get the latest instantiated pod from the API in Kubernetes?

0 Likes

#2

I’m not sure about just returning the latest one, but you should be able to get their timestamp and comparing yourself. There are 2 things you can use .metadata.creationTimestamp or .status.startTime.

Can see this and sort via kubectl:

  • kubectl get pods --sort-by=.metadata.creationTimestamp
  • kubectl get pods --sort-by=.status.startTime
0 Likes

#3

Thanks @mrbobbytables

I searched for an answer to sort them descending to get only the latest one. But I think I sort them ascending and take the latest one. Thanks

0 Likes