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
?
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.
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
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
Allowed keywords are =, ==, !=, in, notin, exists(only the key identifier)
.
==
and =
are synonyms.
in
can be used for OR operation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With