<p>I'm trying to override the node selector for a <code>kubectl run</code>.</p>
<pre><code>kubectl run -it powershell --image=mcr.microsoft.com/powershell:lts-nanoserver-1809-20211215 --restart=Never --overrides='{ &quot;apiVersion&quot;: &quot;v1&quot;, &quot;spec&quot;: { &quot;template&quot;: { &quot;spec&quot;: { &quot;nodeSelector&quot;: { &quot;kubernetes.io/os&quot;: &quot;windows&quot; } } } } }' -- pwsh
</code></pre>
<p>But I get &quot;Invalid Json Path&quot;.</p>
<p>This is my yaml if I do a deployment:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
 ...
spec:
  ...
  template:
    ...
    spec:
      ...
      nodeSelector:
        kubernetes.io/os: windows
</code></pre>
<p>and if I do <code>get pods -o json</code> I get:</p>
<pre><code>{
    &quot;apiVersion&quot;: &quot;v1&quot;,
    &quot;kind&quot;: &quot;Pod&quot;,
    &quot;metadata&quot;: {
        ...
    },
    &quot;spec&quot;: {
        ...
        &quot;nodeSelector&quot;: {
            &quot;kubernetes.io/os&quot;: &quot;windows&quot;
        }
</code></pre>

<p><code>kubectl run</code> is a command to start a <code>Pod</code>. You can read more about it <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands" rel="nofollow noreferrer">here</a></p>
<pre><code>kubectl run -it powershell --image=mcr.microsoft.com/powershell:lts-nanoserver-1809-20211215 --restart=Never --overrides='{ &quot;apiVersion&quot;: &quot;v1&quot;, &quot;spec&quot;: { &quot;template&quot;: { &quot;spec&quot;: { &quot;nodeSelector&quot;: { &quot;kubernetes.io/os&quot;: &quot;windows&quot; } } } } }' -- pwsh
</code></pre>
<p>Using a command above you are trying run a <code>Pod</code> with specification <code>&quot;template&quot;: { &quot;spec&quot;: { </code> which is used only for <code>Deployment</code> and that is why you get an error <code>Invalid Json Path</code>.</p>
<p><code>nodeSelector</code> as you can see in <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector" rel="nofollow noreferrer">documentation</a> could be specify under <code>spec</code> in <code>Pod</code>config file as below:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  nodeSelector:
    disktype: ssd
</code></pre>
<p>When you add <code>--dry-run=client -o yaml</code>to your command to see how the object would be processed, you will see below output which doesn't have <code>nodeSelector</code>:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: powershell
  name: powershell
spec:
  containers:
  - image: mcr.microsoft.com/powershell:lts-nanoserver-1809-20211215
    name: powershell
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}
</code></pre>
<p>To solve your issue, you can delete <code>template</code> and <code>spec</code> from you command which should look as below:</p>
<pre><code>kubectl run -it powershell --image=mcr.microsoft.com/powershell:lts-nanoserver-1809-20211215 --restart=Never --overrides='{ &quot;apiVersion&quot;: &quot;v1&quot;, &quot;spec&quot;: { &quot;nodeSelector&quot;: { &quot;kubernetes.io/os&quot;: &quot;windows&quot; } } }' -- pwsh
</code></pre>
<p>Adding <code>--dry-run=client -o yaml</code>to see what will be changed, you will see that <code>nodeSelector</code> exist:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: powershell
  name: powershell
spec:
  containers:
  - image: mcr.microsoft.com/powershell:lts-nanoserver-1809-20211215
    name: powershell
    resources: {}
  dnsPolicy: ClusterFirst
  nodeSelector:
    kubernetes.io/os: windows
  restartPolicy: Never
status: {}
</code></pre>
