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
?
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:
-
kubectl get po --sort-by='{.firstTimestamp}'
. -
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
kubectl get pods --sort-by=.metadata.creationTimestamp