<p>According to <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#debug" rel="nofollow noreferrer">the Kubernetes docs</a>, you can start a debug version of a container and run a command on it like this:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl debug (POD | TYPE[[.VERSION].GROUP]/NAME) [ -- COMMAND [args...] ]
</code></pre>
<p>But when I try and do this in real life I get the following:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl debug mypod \
  --copy-to=mypod-dev \
  --env='PYTHONPATH=&quot;/my_app&quot;' \
  --set-image=mycontainer=myimage:dev -- python do_the_debugging.py
error: you must specify an existing container or a new image when specifying args.
</code></pre>
<p>If I don't specify <code>-- python do_the_debugging.py</code> I can create the debug container, but then I need a separate command to actually do the debugging:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl exec -it mypod-dev -- python do_the_debugging.py
</code></pre>
<p>Why can't I do this all in one line as the docs seem to specify?</p>
<hr>
<p>Some kubernetes details:</p>
<pre><code>Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;20&quot;, GitVersion:&quot;v1.20.1&quot;, GitCommit:&quot;c4d752765b3bbac2237bf87cf0b1c2e307844666&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2020-12-23T02:22:53Z&quot;, GoVersion:&quot;go1.15.6&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;16+&quot;, GitVersion:&quot;v1.16.15-eks-ad4801&quot;, GitCommit:&quot;ad4801fd44fe0f125c8d13f1b1d4827e8884476d&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2020-10-20T23:27:12Z&quot;, GoVersion:&quot;go1.13.15&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
</code></pre>

LondonRob
<p>Try to add <code>-it</code> and <code>--container</code> flags to your command. In your specific case, it might look like this:<br></p>
<pre><code>$ kubectl debug mypod \
  --copy-to=mypod-dev \
  --env='PYTHONPATH=&quot;/my_app&quot;' \
  --set-image=mycontainer=myimage:dev \
  --container=mycontainer -it -- python do_the_debugging.py
</code></pre>
<p>I am not able to reproduce your exact issue because I don't have the <code>do_the_debugging.py</code> script, but I've created simple example.<br />
First, I created <code>Pod</code> with name <code>web</code> using <code>nginx</code> image:<br></p>
<pre><code>root@kmaster:~# kubectl run web --image=nginx
pod/web created
</code></pre>
<p>And then I ran <code>kubectl debug</code> command to create a copy of <code>web</code> named <code>web-test-1</code> but with <code>httpd</code> image:<br></p>
<pre><code>root@kmaster:~# kubectl debug web --copy-to=web-test-1 --set-image=web=httpd --container=web -it -- bash
If you don't see a command prompt, try pressing enter.
root@web-test-1:/usr/local/apache2#
</code></pre>
<p>Furthermore, I recommend you to upgrade your cluster to a newer version because your client and server versions are very diffrent.<br>
Your <code>kubectl</code> version is <code>1.20</code>, therefore you should have <code>kube-apiserver</code> in version <code>1.19</code> or <code>1.20</code>.
Generally speaking if <code>kube-apiserver</code> is in version <code>X</code>, <code>kubectl</code> should be in version <code>X-1</code> or <code>X</code> or <code>X+1</code>.</p>
