<p>Let's assume I have a node labeled with the labels <code>myKey1: 2</code>, <code>myKey2: 5</code>, <code>myKey3: 3</code>, <code>myKey4: 6</code>. I now want to check if one of those labels has a value greater than 4 and if so schedule my workload on this node. For that I use the following <code>nodeAffinity</code> rule:</p>
<pre class="lang-yaml prettyprint-override"><code> spec:
   containers:
   - name: wl1
     image: myImage:latest
     imagePullPolicy: IfNotPresent
  affinity:
     nodeAffinity:
       requiredDuringSchedulingIgnoredDuringExecution:
         nodeSelectorTerms:
         - matchExpressions:
           - key: myKey1
             operator: Gt
             values:
             - 4
         nodeSelectorTerms:
         - matchExpressions:
           - key: myKey2
             operator: Gt
             values:
             - 4
         nodeSelectorTerms:
         - matchExpressions:
           - key: myKey3
             operator: Gt
             values:
             - 4
         nodeSelectorTerms:
         - matchExpressions:
           - key: myKey4
             operator: Gt
             values:
             - 4
</code></pre>
<p>I would instead love to use something shorter to be able to address a bunch of similar labels like e.g.</p>
<pre class="lang-yaml prettyprint-override"><code>  affinity:
     nodeAffinity:
       requiredDuringSchedulingIgnoredDuringExecution:
         nodeSelectorTerms:
         - matchExpressions:
           - key: myKey*
             operator: Gt
             values:
             - 4
</code></pre>
<p>so basically using a <code>key</code>-wildcard and the different checks connected via a logical <code>OR</code>. Is this possible or is there another solution to check the value of multiple similar labels?</p>

<p>As <a href="https://stackoverflow.com/users/1909531/matthias-m" title="9,753 reputation">Matthias M</a> wrote in the comment:</p>
<blockquote>
<p>I would add an extra label to all nodes, which should match. I think that was the simplest solution. Was that also a solution for you? <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/" rel="nofollow noreferrer">kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node</a></p>
</blockquote>
<p>In your situation, it will actually be easier to just add another key and check only one condition. Alternatively, you can try to use <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#resources-that-support-set-based-requirements" rel="nofollow noreferrer">set-based values</a>:</p>
<blockquote>
<p>Newer resources, such as  <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/" rel="nofollow noreferrer"><code>Job</code></a>,  <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer"><code>Deployment</code></a>,  <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/" rel="nofollow noreferrer"><code>ReplicaSet</code></a>, and  <a href="https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/" rel="nofollow noreferrer"><code>DaemonSet</code></a>, support  <em>set-based</em>  requirements as well.</p>
</blockquote>
<pre class="lang-yaml prettyprint-override"><code>selector:
  matchLabels:
    component: redis
  matchExpressions:
    - {key: tier, operator: In, values: [cache]}
    - {key: environment, operator: NotIn, values: [dev]}

</code></pre>
<blockquote>
<p><code>matchLabels</code>  is a map of  <code>{key,value}</code>  pairs. A single  <code>{key,value}</code>  in the  <code>matchLabels</code>  map is equivalent to an element of  <code>matchExpressions</code>, whose  <code>key</code>  field is &quot;key&quot;, the  <code>operator</code>  is &quot;In&quot;, and the  <code>values</code>  array contains only &quot;value&quot;.  <code>matchExpressions</code>  is a list of pod selector requirements. Valid operators include In, NotIn, Exists, and DoesNotExist. The values set must be non-empty in the case of In and NotIn. All of the requirements, from both  <code>matchLabels</code>  and  <code>matchExpressions</code>  are ANDed together -- they must all be satisfied in order to match.</p>
</blockquote>
<p>For more about it read also <a href="https://stackoverflow.com/questions/55002334/kubernetes-node-selector-regex">this question</a>.</p>
