<p>I noticed a strange behavior while experimenting with <code>kubectl run</code> :</p>
<ul>
<li><p>When the command to be executed is passed as option flag <code>--command -- /bin/sh -c &quot;ls -lah&quot;</code> &gt; <strong>OK</strong></p>
<pre><code>kubectl run nodejs --image=node:lts-alpine \
  --restart=Never --quiet -i --rm \
  --command -- /bin/sh -c &quot;ls -lah&quot;
</code></pre>
</li>
<li><p>When command to be executed is passed in <code>--overrides</code> with <code>&quot;command&quot;: [ &quot;ls&quot;, &quot;-lah&quot; ]</code> &gt; <strong>OK</strong></p>
<pre><code>kubectl run nodejs --image=node:lts-alpine \
  --restart=Never \
  --overrides='
  {
    &quot;kind&quot;: &quot;Pod&quot;,
    &quot;apiVersion&quot;: &quot;v1&quot;,
    &quot;metadata&quot;: {
      &quot;name&quot;: &quot;nodejs&quot;
    },
    &quot;spec&quot;: {
      &quot;volumes&quot;: [
        {
          &quot;name&quot;: &quot;host-volume&quot;,
          &quot;hostPath&quot;: {
            &quot;path&quot;: &quot;/home/dferlay/Sources/df-sdc/web/themes/custom/&quot;
          }
        }
      ],
      &quot;containers&quot;: [
        {
          &quot;name&quot;: &quot;nodejs&quot;,
          &quot;image&quot;: &quot;busybox&quot;,
          &quot;command&quot;: [
            &quot;ls&quot;,
            &quot;-lah&quot;
          ],
          &quot;workingDir&quot;: &quot;/app&quot;,
          &quot;volumeMounts&quot;: [
            {
              &quot;name&quot;: &quot;host-volume&quot;,
              &quot;mountPath&quot;: &quot;/app&quot;
            }
          ],
          &quot;terminationMessagePolicy&quot;: &quot;FallbackToLogsOnError&quot;,
          &quot;imagePullPolicy&quot;: &quot;IfNotPresent&quot;
        }
      ],
      &quot;restartPolicy&quot;: &quot;Never&quot;,
      &quot;securityContext&quot;: {
        &quot;runAsUser&quot;: 1000,
        &quot;runAsGroup&quot;: 1000
      }
    }
  }
  ' \
  --quiet -i --rm
</code></pre>
</li>
<li><p>When the command to be executed is passed as option flag <code>--command -- /bin/sh -c &quot;ls -lah&quot;</code> and <code>--overrides</code> is used for something else (volume for instance) &gt; <strong>KO</strong></p>
<pre><code>kubectl run nodejs --image=node:lts-alpine --restart=Never \
  --overrides='
  {
    &quot;kind&quot;: &quot;Pod&quot;,
    &quot;apiVersion&quot;: &quot;v1&quot;,
    &quot;metadata&quot;: {
      &quot;name&quot;: &quot;nodejs&quot;
    },
    &quot;spec&quot;: {
      &quot;volumes&quot;: [
        {
          &quot;name&quot;: &quot;host-volume&quot;,
          &quot;hostPath&quot;: {
            &quot;path&quot;: &quot;/home/dferlay/Sources/df-sdc/web/themes/custom/&quot;
          }
        }
      ],
      &quot;containers&quot;: [
        {
          &quot;name&quot;: &quot;nodejs&quot;,
          &quot;image&quot;: &quot;busybox&quot;,
          &quot;workingDir&quot;: &quot;/app&quot;,
          &quot;volumeMounts&quot;: [
            {
              &quot;name&quot;: &quot;host-volume&quot;,
              &quot;mountPath&quot;: &quot;/app&quot;
            }
          ],
          &quot;terminationMessagePolicy&quot;: &quot;FallbackToLogsOnError&quot;,
          &quot;imagePullPolicy&quot;: &quot;IfNotPresent&quot;
        }
      ],
      &quot;restartPolicy&quot;: &quot;Never&quot;,
      &quot;securityContext&quot;: {
        &quot;runAsUser&quot;: 1000,
        &quot;runAsGroup&quot;: 1000
      }
    }
  }
  ' \
  --quiet -i --rm --command -- /bin/sh -c &quot;ls -lah&quot;
</code></pre>
</li>
</ul>
<p>So it looks like using <code>--overrides</code> prevents <code>--command</code> to be used.</p>
<p>However, I precisely need to use <code>--command</code> to bypass the array format expected by <code>--overrides</code> (ie. <code>&quot;command&quot;: [ &quot;ls&quot;, &quot;-lah&quot; ]</code>) because in my use case the command is a placeholder and cannot be known in advance.</p>
<ul>
<li>How can I do that ? Is there something I'm missing ?</li>
</ul>
<p>FYI: <code>kubectl version=v1.23.1+k3s2</code></p>

David
<p>You can bypass the array format by using the <code>args</code> field:</p>
<pre><code>&quot;command&quot;: [
 &quot;sh&quot;,
 &quot;-c&quot;
],
&quot;args&quot;: [ &quot;pwd &amp;&amp; id &amp;&amp; node YOUR_COMMAND&quot; ]
</code></pre>
