Kubernetes:按年龄升序显示Pod [英] Kubernetes: Display Pods by age in ascending order
问题描述
我使用以下命令按年龄对豆荚进行排序
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屋!