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
?
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.
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.
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 @chrisAlso 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With