Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes sort pods by age

I can sort my Kubernetes pods by name using:

kubectl get pods --sort-by=.metadata.name

How can I sort them (or other resoures) by age using kubectl?

like image 660
Eugene Platonov Avatar asked Oct 07 '22 09:10

Eugene Platonov


People also ask

What is Kubernetes metadata?

In a Kubernetes environment, metadata can be a crucial tool for organizing and understanding the way containers are orchestrated across your many services, machines, availability zones or (in the future) multiple clouds.

How do I delete pods from kubectl?

Destroy Pod The action of deleting the pod is simple. To delete the pod you have created, just run kubectl delete pod nginx . Be sure to confirm the name of the pod you want to delete before pressing Enter. If you have completed the task of deleting the pod successfully, pod nginx deleted will appear in the terminal.


1 Answers

Pods have status, which you can use to find out startTime.

I guess something like kubectl get po --sort-by=.status.startTime should work.

You could also try:

  1. kubectl get po --sort-by='{.firstTimestamp}'.
  2. kubectl get pods --sort-by=.metadata.creationTimestamp Thanks @chris

Also apparently in Kubernetes 1.7 release, sort-by is broken.

https://github.com/kubernetes/kubectl/issues/43

Here's the bug report : https://github.com/kubernetes/kubernetes/issues/48602

Here's the PR: https://github.com/kubernetes/kubernetes/pull/48659/files

like image 209
vjdhama Avatar answered Oct 08 '22 22:10

vjdhama