Kubernetes:按年龄升序显示Pod [英] Kubernetes: Display Pods by age in ascending order

查看:80
本文介绍了Kubernetes:按年龄升序显示Pod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下命令按年龄对豆荚进行排序

I use below command to sort the pods by age

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

它以降序显示豆荚.我们如何选择升序排序?

It shows up pods in descending order. How can we select sorting order like ascending?

推荐答案

排序的kubectl输出和awk为表视图提供标题.不需要安装额外的工具.

Sorted kubectl output and awk provide the table view with a header. Installation of extra tools is not needed.

# kubectl get pods --sort-by=.status.startTime | awk 'NR == 1; NR > 1 {print $0 | "tac"}'

paulogrell 提供的使用JSON处理器的方法也可以工作,但可能需要付出更多努力:对于某些Linux发行版,您将需要从源代码下载并编译jq.至于jq命令行,我建议将"name"添加到map参数并按"timestamp"排序:

An approach with JSON processor offered by paulogrell works also but could require more effort: for some Linux distributions you'll need to download and compile jq from source code. As for the jq command line I'd suggest to add the "name" to the map parameters and sort by "timestamp":

# kubectl get pods -o json | jq '.items | group_by(.metadata.creationTimestamp) | map({"name": .[0].metadata.name, "timestamp": .[0].metadata.creationTimestamp, "count": length}) | sort_by(.timestamp)'

这篇关于Kubernetes:按年龄升序显示Pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆