Kubernetes sort pods by age

前端 未结 5 924
日久生厌
日久生厌 2021-01-30 05:02

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

相关标签:
5条回答
  • 2021-01-30 05:28
    kubectl get pods --sort-by=.metadata.creationTimestamp
    
    0 讨论(0)
  • 2021-01-30 05:28

    If you are trying to get the most recently created pod you can do the following

    kubectl get pods --sort-by=.metadata.creationTimestamp -o jsonpath='{.items[-1:].metadata.name}'

    Note the -1: gets the last item in the list, then we return the pod name

    0 讨论(0)
  • 2021-01-30 05:33

    I have created KUBESORT exactly for these kinds of sorting purposes.
    Pls have a try,

    https://github.com/AATHITH/kubesort

    0 讨论(0)
  • 2021-01-30 05:40

    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

    0 讨论(0)
  • 2021-01-30 05:44

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

    kubectl get po --sort-by=.metadata.creationTimestamp -n <<namespace>> | tac
    
    0 讨论(0)
提交回复
热议问题