codec
codec

Reputation: 8806

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

My namespace has some custom metadata labels. Some have the labels some don't. Is there any way to get the namespaces which has a particular label using kubectl?

Upvotes: 3

Views: 4879

Answers (1)

Michael Hausenblas
Michael Hausenblas

Reputation: 13941

Yes. Like so:

$ 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

Note: I could have also used -l=this=thing in the last command to specify both key and value required to match.

Upvotes: 6

Related Questions