Kubernetes sort pods by age

前端 未结 5 969
日久生厌
日久生厌 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

    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

提交回复
热议问题