首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >基于kubernetes集的标签选择器

基于kubernetes集的标签选择器
EN

Stack Overflow用户
提问于 2022-10-25 15:45:52
回答 1查看 61关注 0票数 0

我想使用基于集合的选择器来过滤豆荚。

以下豆荚

代码语言:javascript
运行
复制
+ kubectl get pods --show-labels
NAME                                            READY   STATUS    RESTARTS        AGE     LABELS
csi-cephfsplugin-dk7g6                          3/3     Running   0               7d12h   app=csi-cephfsplugin,controller-revision-hash=758476fc67,pod-template-generation=12
csi-cephfsplugin-jlcpv                          3/3     Running   0               7d12h   app=csi-cephfsplugin,controller-revision-hash=758476fc67,pod-template-generation=12
csi-cephfsplugin-ll85n                          3/3     Running   0               7d12h   app=csi-cephfsplugin,controller-revision-hash=758476fc67,pod-template-generation=12
csi-cephfsplugin-pbf5n                          3/3     Running   0               7d12h   app=csi-cephfsplugin,controller-revision-hash=758476fc67,pod-template-generation=12
csi-cephfsplugin-provisioner-6f7ffd894d-9jt8c   6/6     Running   0               7d12h   app=csi-cephfsplugin-provisioner,pod-template-hash=6f7ffd894d
csi-cephfsplugin-provisioner-6f7ffd894d-q74x2   6/6     Running   0               7d12h   app=csi-cephfsplugin-provisioner,pod-template-hash=6f7ffd894d
csi-cephfsplugin-provisioner-6f7ffd894d-vn8m7   6/6     Running   0               7d12h   app=csi-cephfsplugin-provisioner,pod-template-hash=6f7ffd894d
csi-cephfsplugin-sqkz6                          3/3     Running   0               7d12h   app=csi-cephfsplugin,controller-revision-hash=758476fc67,pod-template-generation=12
csi-rbdplugin-2qf4v                             3/3     Running   0               7d12h   app=csi-rbdplugin,controller-revision-hash=79c748c46c,pod-template-generation=12
csi-rbdplugin-5f8ng                             3/3     Running   0               7d12h   app=csi-rbdplugin,controller-revision-hash=79c748c46c,pod-template-generation=12
csi-rbdplugin-6b9l2                             3/3     Running   0               7d12h   app=csi-rbdplugin,controller-revision-hash=79c748c46c,pod-template-generation=12
csi-rbdplugin-6whd8                             3/3     Running   0               7d12h   app=csi-rbdplugin,controller-revision-hash=79c748c46c,pod-template-generation=12
csi-rbdplugin-p67v7                             3/3     Running   0               7d12h   app=csi-rbdplugin,controller-revision-hash=79c748c46c,pod-template-generation=12
csi-rbdplugin-provisioner-7dffff7f4d-47bsb      7/7     Running   0               7d12h   app=csi-rbdplugin-provisioner,pod-template-hash=7dffff7f4d
csi-rbdplugin-provisioner-7dffff7f4d-mdzfv      7/7     Running   0               7d12h   app=csi-rbdplugin-provisioner,pod-template-hash=7dffff7f4d
csi-rbdplugin-provisioner-7dffff7f4d-zh76c      7/7     Running   0               7d12h   app=csi-rbdplugin-provisioner,pod-template-hash=7dffff7f4d

< many other pods >

我想用包含关键字csi的标签过滤豆荚,

代码语言:javascript
运行
复制
kubectl get pods -l 'app in (csi)'

但要犯错误

代码语言:javascript
运行
复制
error: name cannot be provided when a selector is specified

知道吗?

EN

回答 1

Stack Overflow用户

发布于 2022-10-25 19:33:21

您可以使用awk来匹配荚名。

代码语言:javascript
运行
复制
kubectl get pods --no-headers --show-labels | awk '{if ($NF ~ ".*app=csi.*") print $0}'

$NF是一个变量,表示文件/流中的最后一列。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74196783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档