kubectl:将自定义列输出与地图一起使用 [英] kubectl: Use custom-columns output with maps

查看:291
本文介绍了kubectl:将自定义列输出与地图一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将注释的特定值添加到kubectl自定义列字段中.我可以在这样的资源上获取所有当前注释:

I want to get the specific value of an annotation into a kubectl custom columns field. I can get all the current annotations on a resource like so:

kubectl get pvc -o custom-columns=NAME:.metadata.name,"ANNOTATIONS":.metadata.annotations -n monitoring

这将返回一个地图:

NAME                                 ANNOTATIONS
prometheus-k8s-db-prometheus-k8s-0   map[pv.kubernetes.io/bind-completed:yes pv.kubernetes.io/bound-by-controller:yes volume.beta.kubernetes.io/storage-provisioner:kubernetes.io/aws-ebs]
prometheus-k8s-db-prometheus-k8s-1   map[pv.kubernetes.io/bind-completed:yes pv.kubernetes.io/bound-by-controller:yes volume.beta.kubernetes.io/storage-provisioner:kubernetes.io/aws-ebs]

考虑到kubectl -o custom-columns据我所知使用JSONpath,我认为我可以做到这一点:

And considering kubectl -o custom-columns uses JSONpath to the best of my knowledge, I figured I could do this:

kubectl get pvc -o custom-columns=NAME:.metadata.name,"ANNOTATIONS":".metadata.annotations['pv.kubernetes.io/bind-completed']" -n monitoring

但是似乎没有.有办法吗?

But it seems not. Is there a way to do this?

推荐答案

好的,我知道了.比我想象的要容易.

Okay, I figured this out. It's easier than I thought.

Annotations是返回时的标准JSON元素.问题是kubectl的JSONPath解析器在元素中存在点问题,因此您只需要转义它们即可.这是一个示例:

Annotations is a standard JSON element when it's returned. The problem is that kubectl's JSONPath parser has problems with dots in elements, so you just have to escape them. Here's an example:

kubectl get pvc -o custom-columns=NAME:.metadata.name,"ANNOTATIONS":".metadata.annotations.pv\.kubernetes\.io/bind-completed" -n monitoring

NAME                                 ANNOTATIONS
prometheus-k8s-db-prometheus-k8s-0   yes
prometheus-k8s-db-prometheus-k8s-1   yes

这篇关于kubectl:将自定义列输出与地图一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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