kubernetes 打印特定列

kubernetes to print specific columns

只需要在 kubernetes 中使用 JSONPATH 查询的特定列:

NAME  STATUS    ROLES   AGE VERSION
1     Ready     master  35d v1.18.6
2     Ready     <none>  35d v1.18.6
3     Ready     <none>  35d v1.18.6             
4     Ready     <none>  35d v1.18.6             
5     Ready     master  35d v1.18.6             
6     Ready     <none>  35d v1.18.6

所需的输出应如下所示:

NAME    VERSION
1       v1.18.6
2       v1.18.6
3       v1.18.6
4       v1.18.6
5       v1.18.6 
6       v1.18.6

上述问题的答案是:

  • $ kubectl get node -o=jsonpath='{range.items[*]}{.metadata.selfLink} {"\t"} {.status.nodeInfo.kubeletVersion}{"\n"}{end}'

它将产生输出:

01    v1.18.6
02    v1.18.6
03    v1.18.6
04    v1.18.6
05    v1.18.6

进一步排序:

  • $ kubectl get node -o=custom-columns=NODE:.metadata.selfLink

  • $ kubectl get node -o=custom-columns=VERSION:.status.nodeInfo.kubeletVersion

    kubectl get node -o=custom-columns=NODE:.metadata.selfLink,VERSION:.status.nodeInfo.kubeletVersion N