有什么方法可以根据特定的元数据标签获取名称空间

Is there any way to get namespaces based on a particular metadata label

我的命名空间有一些自定义元数据标签。有些有标签有些没有。有什么方法可以使用 kubectl 获取具有特定标签的命名空间吗?

是的。像这样:

$ kubectl create ns nswithlabels

$ kubectl label namespace nswithlabels this=thing

$ kubectl describe ns/nswithlabels
Name:         nswithlabels
Labels:       this=thing
Annotations:  <none>
Status:       Active

No resource quota.

No resource limits.

$ kubectl get ns -l=this
NAME           STATUS    AGE
nswithlabels   Active    6m

注意:我也可以在最后一个命令中使用 -l=this=thing 来指定匹配所需的键和值。