Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.6k views
in Technique[技术] by (71.8m points)

kubernetes - you must specify an existing container or a new image when specifying args

According to the Kubernetes docs, you can start a debug version of a container and run a command on it like this:

$ kubectl debug (POD | TYPE[[.VERSION].GROUP]/NAME) [ -- COMMAND [args...] ]

But when I try and do this in real life I get the following:

$ kubectl debug mypod 
  --copy-to=mypod-dev 
  --env='PYTHONPATH="/my_app"' 
  --set-image=mycontainer=myimage:dev -- python do_the_debugging.py
error: you must specify an existing container or a new image when specifying args.

If I don't specify -- python do_the_debugging.py I can create the debug container, but then I need a separate command to actually do the debugging:

kubectl exec -it mypod-dev -- python do_the_debugging.py

Why can't I do this all in one line as the docs seem to specify?


Some kubernetes details:

Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.1", GitCommit:"c4d752765b3bbac2237bf87cf0b1c2e307844666", GitTreeState:"clean", BuildDate:"2020-12-23T02:22:53Z", GoVersion:"go1.15.6", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16+", GitVersion:"v1.16.15-eks-ad4801", GitCommit:"ad4801fd44fe0f125c8d13f1b1d4827e8884476d", GitTreeState:"clean", BuildDate:"2020-10-20T23:27:12Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try to add -it and --container flags to your command. In your specific case, it might look like this:

$ kubectl debug mypod 
  --copy-to=mypod-dev 
  --env='PYTHONPATH="/my_app"' 
  --set-image=mycontainer=myimage:dev 
  --container=mycontainer -it -- python do_the_debugging.py

I am not able to reproduce your exact issue because I don't have the do_the_debugging.py script, but I've created simple example.
First, I created Pod with name web using nginx image:

root@kmaster:~# kubectl run web --image=nginx
pod/web created

And then I ran kubectl debug command to create a copy of web named web-test-1 but with httpd image:

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#

Furthermore, I recommend you to upgrade your cluster to a newer version because your client and server versions are very diffrent.
Your kubectl version is 1.20, therefore you should have kube-apiserver in version 1.19 or 1.20. Generally speaking if kube-apiserver is in version X, kubectl should be in version X-1 or X or X+1.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...