Reputation: 2430
From VS Code on my local machine I am trying to attach a debugger to a remote process running in a container/Pod, or attach to a gdb/gdbserver attached to a process running in a container/Pod.
The project is written in C++, and VS Code has support for debugging processes using GDB.
My topology looks like this:
----------- --------------- ------------------------------------
| localhost | <---> | access server | <--> | worker node |
| (VS Code) | | (ubuntu box) | | (k8s node) <-> POD <-> Container |
----------- --------------- ------------------------------------
Access to the container/Pod has to be done via "access server" (aka. jumpbox) for security reasons. VS Code is configured and is able to connect to the worker node via access server (via VS Code ssh config option -ProxyCommand ssh -W %h:%p Access_Server
), have K8s extension working too and can see the cluster info and interact with it.
In terms of connectivity, I can get VS Code to connect to the worker node but not to Container itself. Where debugger could be attached to running process.
I have tried running gdbserver on the container and opening the required port, and since VS Code can connect to the node in theory it should see the gdbserver but this fails with nondescript error.
I have tried to use gdb from an interactive shell, but due to the nature and scope of project a modern gui debugger is really my best option for success.
This is my first project in a cloud env so its a bit new to me, please do not assume I know things, and kindly provide guidance if it seems like I may be unaware of something you believe is obvious. I have inherited a project with not much info about devops, and no one here to ask. I've tried following some guides but nothing I've tried has really worked.
What would be the most appropriate approach to debugging given such a setup?
Upvotes: 4
Views: 1662
Reputation: 82
You shuold use kubectl port forward functionality, to forward your local gdb connection to the gdbserver running inside the container.
Another solution that might work: If you have KubeAPI access and are running on Linux/macOS (or can use WSL) I'd suggest to check out https://marketplace.visualstudio.com/items?itemName=MetalBear.mirrord - It enables you to run your process locally in the context of the existing pod, then you can attach a debugger to it (or just run it using the debugger with mirrord)
Full disclosure, I'm developing mirrord.
Upvotes: 1