How to specify not equal selector in kubernetes service definition yaml? How to specify not equal selector in kubernetes service definition yaml? kubernetes kubernetes

How to specify not equal selector in kubernetes service definition yaml?


I've did some test but I am afraid it is not possible. As per docs API supports two types of selectors:

kubeclt allows to use operators like =,== and !=. So it works when you are using $ kubectl get pods --selector property1=dev,property2!=admin.

Configuration which you want to apply would work in set-based option as it supports in, notin and exists:

environment in (production, qa)

tier notin (frontend, backend)

partition

!partition

Unfortunately set-based is supported only by newer resurces as Job, Deployment, Replica Set and Deamon Set but is not supporting services.

More information about this can be found here.

Even if you will set selector in YAML as:

property2: !value 

In service, property2 will be without any value.

Selector: property1=dev,property2=

As additional information , is recognized as AND in services.

As I am not aware how you are managing your cluster, the only thing I can advise is to redefine labels to use only AND as logical operator.