<p>I was wondering if there was a one line kubectl command to add the nodeSelector in the pod yaml? (I have already attached a label to the node) I am trying to automate this and hence I want to avoid manually downloading the yaml file and adding the nodeSelector. Any ideas using sed or kubectl replace would be appreciated.</p>

Contraboy
<p>You can add <code>nodeSelector</code> in pod spec.</p>
<p>As the k8s <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector" rel="nofollow noreferrer">doc</a> : nodeSelector is the simplest recommended form of node selection constraint. nodeSelector is a field of PodSpec. It specifies a map of key-value pairs. For the pod to be eligible to run on a node, the node must have each of the indicated key-value pairs as labels (it can have additional labels as well). The most common usage is one key-value pair.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  nodeSelector:
    disktype: ssd
</code></pre>
<h1>update</h1>
<p>I found a way to do this:</p>
<pre><code>kubectl run --generator=run-pod/v1 -ti --rm test --image=ubuntu:20.04 --overrides='{&quot;spec&quot;: { &quot;nodeSelector&quot;: {&quot;nodename&quot;: &quot;test-node&quot;}}}'
</code></pre>
