Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can the OR selector be used with labels in Kubernetes?

Tags:

kubernetes

How the OR expression can be used with selectors and labels?

  selector:
    app: myapp
    tier: frontend

The above matches pods where labels app==myapp AND tier=frontend.

But the OR expression can be used?

app==myapp OR tier=frontend?

like image 629
Tevin J Avatar asked Sep 03 '17 23:09

Tevin J


People also ask

How do you identify a pod label?

You can also do a kubectl get pod example-pod -o yaml to see all of the fields and labels. Let us now add another label to the above pod using the kubectl command. kubectl label --overwrite pods example-pod env=prod will update the value of key env in the labels, and if the label does not exist, it will create one.


3 Answers

Now you can do that :

kubectl get pods -l 'environment in (production, qa)' 

https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#list-and-watch-filtering

like image 94
Pasc23 Avatar answered Sep 29 '22 06:09

Pasc23


OR isn't supported in your case.

You can try the set-based label selector. Refer to the following link, https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#resources-that-support-set-based-requirements

like image 41
Benjamin Avatar answered Sep 29 '22 05:09

Benjamin


Allowed keywords are =, ==, !=, in, notin, exists(only the key identifier). == and = are synonyms. in can be used for OR operation.

like image 43
Smruti Ranjan Senapati Avatar answered Sep 29 '22 07:09

Smruti Ranjan Senapati