<p>I am working with Minikube and I have alpine pod with one container.<br>
When I run:<br>
<code>kubectl exec -it -v=6 alpinec1-7c65db48b4-v2gpc /bin/sh</code>  </p>

<p>I receive a shell and I can run any command (<code>ifconfig</code>, etc.) inside it.  </p>

<p>But when I tried to run <code>sh</code> with <code>-c</code> it failed:</p>

<pre><code>root:~# kubectl exec -it -v=6 alpinec1-7c65db48b4-v2gpc /bin/sh -c 'ifconfig'
I0722 05:45:25.091111   80392 loader.go:357] Config loaded from file /home/root/.kube/config
I0722 05:45:25.111876   80392 round_trippers.go:405] GET https://192.168.190.143:8443/api/v1/namespaces/default/pods/alpinec1-7c65db48b4-v2gpc 200 OK in 16 milliseconds
I0722 05:45:25.232564   80392 round_trippers.go:405] POST https://192.168.190.143:8443/api/v1/namespaces/default/pods/alpinec1-7c65db48b4-v2gpc/exec?command=%2Fbin%2Fsh&amp;container=ifconfig&amp;container=ifconfig&amp;stdin=true&amp;stdout=true&amp;tty=true 400 Bad Request in 13 milliseconds
                                                                     I0722 05:45:25.232921   80392 helpers.go:201] server response object: [{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "container ifconfig is not valid for pod alpinec1-7c65db48b4-v2gpc",
  "reason": "BadRequest",
  "code": 400
}]
F0722 05:45:25.233095   80392 helpers.go:119] Error from server (BadRequest): container ifconfig is not valid for pod alpinec1-7c65db48b4-v2gpc
</code></pre>

<p>kubectl interprets the <code>-c</code> flag not as a flag for <code>ifconfig</code>, but as a flag for the <code>kubectl exec</code> command itself -- which specifies the exact container of a Pod in which the command should be executed; this is also the reason that <code>kubectl</code> looks for a <em>container</em> named "ifconfig" in your Pod. See <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#exec" rel="noreferrer">the documentation</a> for more information.</p>

<p>Instead, use <code>--</code> to denote flags that should not be interpreted by <code>kubectl exec</code> any more but instead be passed to the invoked command (<code>ifconfig</code>, in this case) as-is:</p>

<pre><code>$ kubectl exec -it -v=6 alpinec1-7c65db48b4-v2gpc -- /bin/sh -c 'ifconfig'
</code></pre>

<p>Also note that in this case, you do not really need to invoke ifconfig from a shell; you could also just directly call <code>ifconfig</code> without using <code>/bin/sh</code>:</p>

<pre><code>$ kubectl exec -it -v=6 alpinec1-7c65db48b4-v2gpc -- ifconfig
</code></pre>
