如何将kubectl描述的输出格式化为JSON [英] How to format the output of kubectl describe to JSON

查看:731
本文介绍了如何将kubectl描述的输出格式化为JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

kubectl get命令具有此标志-o来格式化输出.

kubectl get command has this flag -o to format the output.

是否有类似的方式来格式化kubectl describe命令的输出?

Is there a similar way to format the output of the kubectl describe command?

例如:

kubectl describe -o="jsonpath={...}" pods my-rc

将为my-rc复制控制器中的Pod列表打印JSON格式.但是describe命令不接受-o.

would print a JSON format for the list of pods in my-rc replication controller. But -o is not accepted for the describe command.

推荐答案

kubectl describe不支持-o或等效版本.它应该是人类可读的,而不是脚本友好的.您可以使用kubectl get pods -l <selector_of_your_rc> -o <output_format>实现您所描述的内容,例如:

kubectl describe doesn't support -o or equivalent. It's meant to be human-readable rather than script-friendly. You can achieve what you described with kubectl get pods -l <selector_of_your_rc> -o <output_format>, for example:

$ kubectl get pods -l app=guestbook,tier=frontend -o name
pod/frontend-a4kjz
pod/frontend-am1ua
pod/frontend-yz2dq

这篇关于如何将kubectl描述的输出格式化为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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