<p>I have a Kubernetes cluster where a resource is available in multiple types.</p>
<p>They are labeled <code>r_Type=r1</code>, <code>r_Type=r2</code>, and so on.</p>
<p>I need to start a pod that can run on a number of those types. For just one type, the corresponding YAML file would be simple:</p>
<pre class="lang-yaml prettyprint-override"><code>nodeSelector:
    r_Type: r1
</code></pre>
<p>How do I write that if the pod can run on multiple of these resources? I see in the <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#set-based-requirement" rel="nofollow noreferrer">Kubernetes documentation</a> on labels that there is an 'in' set notation. But how do I write it? The following code does not look right:</p>
<pre class="lang-yaml prettyprint-override"><code>nodeSelector:
    r_Type in (r1, r2)
</code></pre>
<p>That does not seem like valid YAML.</p>
<p>Can someone provide an example of how to achieve this?</p>

Hans
<p>You can't use the set syntax in a <code>nodeSelector</code>; that field is a simple <code>key: value</code> map:</p>
<pre><code>$ kubectl explain pod.spec.nodeSelector
KIND:     Pod
VERSION:  v1

FIELD:    nodeSelector &lt;map[string]string&gt;

DESCRIPTION:
     NodeSelector is a selector which must be true for the pod to fit on a node.
     Selector which must match a node's labels for the pod to be scheduled on
     that node. More info:
     https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
</code></pre>
<p>The expression <code>map[string]string</code> is a Go type expression, and it means the value is a map of string keys to string values.</p>
<p>If you read through &quot;<a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/" rel="nofollow noreferrer">Assigning Pods to Nodes</a>&quot;, you'll note that there are alternatives to <code>nodeSelector</code> that have more expressive syntax. For example, the <code>nodeAffinity</code> field supports <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#resources-that-support-set-based-requirements" rel="nofollow noreferrer"><code>matchExpressions</code></a>, which do support set-based requirements:</p>
<pre><code>spec:
  affinity:
    nodeAffinitiy:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: r_Type
            operator: In
            values:
            - r1
            - r2
</code></pre>
<p>See also <code>kubectl explain</code>:</p>
<pre><code>$ kubectl explain pod.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms.matchExpressions
KIND:     Pod
VERSION:  v1

RESOURCE: matchExpressions &lt;[]Object&gt;

DESCRIPTION:
     A list of node selector requirements by node's labels.

     A node selector requirement is a selector that contains values, a key, and
     an operator that relates the key and values.

FIELDS:
   key  &lt;string&gt; -required-
     The label key that the selector applies to.

   operator     &lt;string&gt; -required-
     Represents a key's relationship to a set of values. Valid operators are In,
     NotIn, Exists, DoesNotExist. Gt, and Lt.

     Possible enum values:
     - `&quot;DoesNotExist&quot;`
     - `&quot;Exists&quot;`
     - `&quot;Gt&quot;`
     - `&quot;In&quot;`
     - `&quot;Lt&quot;`
     - `&quot;NotIn&quot;`

   values       &lt;[]string&gt;
     An array of string values. If the operator is In or NotIn, the values array
     must be non-empty. If the operator is Exists or DoesNotExist, the values
     array must be empty. If the operator is Gt or Lt, the values array must
     have a single element, which will be interpreted as an integer. This array
     is replaced during a strategic merge patch.
</code></pre>
