Kubernetes sort pods by age

╄→尐↘猪︶ㄣ 提交于 2019-12-20 08:56:01

问题


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?


回答1:


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 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




回答2:


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



回答3:


If you want to sort them in reverse order based on the age:

kubectl get po --sort-by=.metadata.creationTimestamp -n <<namespace>> | tac


来源:https://stackoverflow.com/questions/45310287/kubernetes-sort-pods-by-age

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!