I run a local Kubernetes kind cluster.
If I use "Dev Containers: Attach to Running Containers …", then I only see control-plane container of the kind cluster (foo-control-plane).
But I don’t see the containers (pods) which are inside the control-plane.
Is there a way to connect via Dev Containers to a container in a local minikube/kind cluster?
My goal is to debug a Go application with Delve
2
Answers
Since your goal is to debug a Go application with Delve (remotely), I think you should refer to How can I use Delve for remote debugging? and Debugging with Go extension instead.
Most of the guides below are copied from those docs.
Start a headless instance of Delve inside the pod like this:
Note: I encountered an error when running this command in a pod:
Could not attach to pid 1: this could be caused by a kernel security setting, try writing "0" to /proc/sys/kernel/yama/ptrace_scope
. In order to try the solution myself, I created a docker image to start the Delve server directly like this (seeDockerfile
in the attachments section):Forward the port to make the debug server available from outside:
In vscode, create the
.vscode/launch.json
file:It’s important to set
substitutePath
correctly so that you can see the source code in vscode. Since the source code of my demo app is copied to/app
and built from there (built with docker), the path recorded in the binary is/app/main.go
, so I have to map from${workspaceFolder}
to/app
.In vscode, start debugging with this configuration.
Attachments
main.go
:Dockerfile
:docker build -t goapp:1.0 -f Dockerfile .
.kind load docker-image goapp:1.0
.goapp.yaml
:kubectl apply -f goapp.yaml
.Regarding this question, please see Attach to a container in a Kubernetes cluster: