<p>Is there a way to apply a <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector" rel="nofollow noreferrer">nodeSelector</a> via command? (like <code>kubectl apply</code>)</p>
<p>It would be nice if it is applicable on running deployments or namespaces, otherwise applying to running pods is also fine.</p>
<p>Any tips are appreciated</p>

Nur1
<p>You can use the kubectl patch command, like this:</p>
<p><code>kubectl patch deployments nginx-deployment -p '{&quot;spec&quot;: {&quot;template&quot;: {&quot;spec&quot;: {&quot;nodeSelector&quot;: {&quot;kubernetes.io/hostname&quot;: &quot;node-2&quot;}}}}}'</code></p>
<p>After successful patch all pods of the deployment will be restarted on a node matching the selector.</p>
