kubectl按pod创建时间排序获取列表

按时间排序,可以更快地找到最近更新的pod

基于当前ns

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

基于整个集群

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

也可以按Pod的状态排序,快速找到不正常的Pod

1
kubectl get pods --sort-by=.status.phase

–sort-by可以对k8s所有的api对象的进行排序(只要对应的字段是integer或者string)

1
2
3
--sort-by='': If non-empty, sort list types using this field specification.  
The field specification is expressed as a JSONPath expression (e.g. '{.metadata.name}').
The field in the API resource specified by this JSONPath expression must be an integer or a string.