0

I am trying to use VS Code to debug kubernetes pod in python. I have successfully debug one pod with Kuberentes: Debug (Attach) command. However, when I tried to debug another pod with the same command, I got error:

[E1105 11:54:06.281402 25535 portforward.go:400] an error occurred forwarding 10000 -> 5678: error forwarding port 5678 tp pod

The same port forwarding works fine for the first pod. Only when I try to attach another port, I got the error. Before I tried to attach the second pod, I have disattached the first pod already.

I suspect that the port is still being used by the first pod so the second pod could not be forwarded.
Does anyone know how to change the port number in vscode and how to fix this problem? Thanks

Kamafeather
  • 8,663
  • 14
  • 69
  • 99
  • Port is configured in launchSettings.json file, property named debugPort, you could try changing that – Nikita Chayka Nov 05 '20 at 20:22
  • Thank you very much for your help. I have searched in my computer and could not find launchSettings.json. Do you know where is it or how to create it? – Frank Wang Nov 05 '20 at 22:11
  • What extension you using to attach VScode to kuber? – Nikita Chayka Nov 05 '20 at 22:40
  • I use Kubernetes extension from Microsoft. version is v1.2.1 – Frank Wang Nov 05 '20 at 22:58
  • Oh, ok, thought of different one. you could check here - https://github.com/Azure/vscode-kubernetes-tools/blob/master/debug-on-kubernetes.md there is an Extension setting named vs-kubernetes.nodejs-debug-port where you could specify a port, only thing that is not really clear, is that should or should not you replace there "nodejs" by "python" for your case – Nikita Chayka Nov 05 '20 at 23:30
  • Thank you very much for your help. After many try and error, I figured it out the reason. To debug the kubernetes pod in python, we have to put ptvsd.enable_attach() and other ptvsd command in the main thread. – Frank Wang Nov 06 '20 at 00:53
  • I solved the issue after try and error. To fix this issue, we have to put the ptvsd command in main thread. – Frank Wang Nov 06 '20 at 15:29
  • @FrankWang if you're looking for a way to do this without modifying your pods' code, I wrote an open source project that does this: https://docs.robusta.dev/master/catalog/actions/python-troubleshooting.html#python-debugger – Natan Yellin Dec 30 '21 at 14:53

0 Answers0