<p>I am using a command for pod creation plus node selection</p>
<pre><code>kubectl run newpod --image image1 --command run over --overrides='{ &quot;apiVersion&quot;: &quot;v1&quot;, &quot;spec&quot;: { &quot;template&quot;: { &quot;spec&quot;: { &quot;nodeSelector&quot;: { &quot;kubernetes.io/hostname&quot;: &quot;one-worker-node&quot; } } } } }'
</code></pre>
<p>the problem is it that it runs on one worker node named &quot;one-worker-node&quot;. I could not make it run for two or more worker nodes. like</p>
<pre><code>kubectl run newpod --image image1 --command run over --overrides='{ &quot;apiVersion&quot;: &quot;v1&quot;, &quot;spec&quot;: { &quot;template&quot;: { &quot;spec&quot;: { &quot;nodeSelector&quot;: { &quot;kubernetes.io/hostname&quot;: &quot;one-worker-node&quot; : &quot;second-worker-node&quot;} } } } }'
</code></pre>

<p>You can't do it with <code>nodeSelector</code>, because you would need to pass two key-values, with the same key. Something like this:</p>
<pre><code>kubectl run newpod --image image1 --overrides='{ &quot;apiVersion&quot;: &quot;v1&quot;, &quot;spec&quot;: { &quot;nodeSelector&quot;: { &quot;kubernetes.io/hostname&quot;: &quot;one-worker-node&quot;, &quot;kubernetes.io/hostname&quot;: &quot;second-worker-node&quot; } } }'
</code></pre>
<p>Which is equivalent to this:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    run: nginx
spec:
  containers:
  - name: nginx
    image: nginx
  nodeSelector:
    kubernetes.io/hostname: one-worker-node
    kubernetes.io/hostname: second-worker-node
</code></pre>
<p>If you'd deploy this pod, only the last label will take effect, as the first label will be overritten in the Pod yaml.</p>
<p>So, you would use <code>nodeAffinity</code>. This one should work from the command line:</p>
<pre><code>kubectl run newpod --image image1 --overrides='{ &quot;spec&quot;: { &quot;affinity&quot;: { &quot;nodeAffinity&quot;: { &quot;requiredDuringSchedulingIgnoredDuringExecution&quot;: { &quot;nodeSelectorTerms&quot;: [{ &quot;matchExpressions&quot;: [{ &quot;key&quot;: &quot;kubernetes.io/hostname&quot;,  &quot;operator&quot;: &quot;In&quot;, &quot;values&quot;: [ &quot;one-worker-node&quot;, &quot;second-worker-node&quot; ]} ]} ]} } } } }'
</code></pre>
<p>Which is equivalent to this:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: newpod
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - one-worker-node
            - second-worker-node
  containers:
  - name: image1
    image: image1
</code></pre>
<p>You can add all your candidates to the <code>values</code>. Also you might want to make it a preference with <code>preferredDuringSchedulingIgnoredDuringExecution</code>, or have both; a preference and a requirement.</p>
<p><strong>PoC</strong></p>
<pre><code>root@master-1-v1-20:~# kubectl get no
NAME             STATUS   ROLES      AGE   VERSION
master-1-v1-20   Ready    master     43d   v1.20.2
worker-1-v1-20   Ready    worker-1   42d   v1.20.2
worker-2-v1-20   Ready    worker-2   42d   v1.20.2
root@master-1-v1-20:~# grep affinity -A8 affinity.yaml 
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - worker-1-v1-20 
root@master-1-v1-20:~# kubectl create -f affinity.yaml 
pod/newpod created
root@master-1-v1-20:~# kubectl get po newpod -owide
NAME     READY   STATUS    RESTARTS   AGE   IP                NODE             NOMINATED NODE   READINESS GATES
newpod   1/1     Running   0          18s   192.168.127.102   worker-1-v1-20   &lt;none&gt;           &lt;none&gt;
</code></pre>
<p>I change the name to <code>newpod-2</code> and configure it to run on the second node:</p>
<pre><code>root@master-1-v1-20:~# vim affinity.yaml 
root@master-1-v1-20:~# grep affinity -A8 affinity.yaml 
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - worker-2-v1-20 
root@master-1-v1-20:~# kubectl create -f affinity.yaml 
pod/newpod-2 created
root@master-1-v1-20:~# kubectl get po newpod newpod-2 -owide
NAME       READY   STATUS    RESTARTS   AGE     IP                NODE             NOMINATED NODE   READINESS GATES
newpod     1/1     Running   0          4m26s   192.168.127.102   worker-1-v1-20   &lt;none&gt;           &lt;none&gt;
newpod-2   1/1     Running   0          3m25s   192.168.118.172   worker-2-v1-20   &lt;none&gt;           &lt;none&gt;
</code></pre>
