kubectl 的标签选择器

kubectl 的标签选择器

(金庆的专栏 2021.1)

摘自:Kubenetes in Action

首先可以给 pod 添加 label:

kubectl label pod mypod abc=123

显示 label:

kubectl get pod --show-labels

显示部分 label:

kubectl get pod -L app,abc

更改

kubeclt label --overwrite pod mypod abc=456

删除不需要 --overwrite

kubectl label pod mypod abc-

有了标签后,可以

  • 选择没有特定标签
  • 选择有特定标签
  • 选择有特定标签并且值相等或值不等

列出 abc=123 的 pod

kubectl get pod -l abc=123

列出没有 abc 标签的 pod

kubectl get pod -l '!abc'

注意 Linux shell 叹号必须用引号括起来:

还可以这样:

kubectl get pod -l 'abc!=123'
kubectl get pod -l 'abc in (123,456,ddd)'
kubectl get pod -l 'abc notin (123,456)'

如果是多个 -l, 则仅最后一个 -l 有效.

kubectl get pod -l abc -l efg

同时满足:

kubectl get pod -l abc=123,efg=456

好像没有办法表示或者关系, 见:
https://v1-16.docs.kubernetes.io/docs/concepts/overview/working-with-objects/labels/

Caution: For both equality-based and set-based conditions there is no logical OR (||) operator. Ensure your filter statements are structured accordingly.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值