kubernetes - kubernetes to print specific columns
问题描述
Need only specific columns using JSONPATH query in kubernetes:
$ kubectl get node
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
Desired output should look like this:
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
解决方案
Th answer to above question is:
$ kubectl get node -o=jsonpath='{range.items[*]}{.metadata.selfLink} {"\t"} {.status.nodeInfo.kubeletVersion}{"\n"}{end}'
It will produce output:
01 v1.18.6
02 v1.18.6
03 v1.18.6
04 v1.18.6
05 v1.18.6
For further sorting:
$ 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
推荐阅读
- javascript - 这个 https.request 示例有什么问题?
- cmake - 有没有办法为 FetchContent 目标获取 -isystem ?
- python - 使用字典获取映射值
- php - 比较php中两个数组的数据
- npgsql - 无法从存储过程中获取结果
- angular - Angular 1.5 中基于比较日期的条件样式
- node.js - Node、Nuxt、MongoDB、nuxt/auth - 如何获取用户 _id?
- javascript - Javascript:如何将 getComputedStyles() 生成的 CSS 样式设置为按钮
- unity3d - 将 .psb 中的矢量形状导入 Unity 时出现问题?
- python - Kivy 如果在特定时间按下按钮,请执行此操作