What is DebugHero
DebugHero lets you debug a Go service that runs in Kubernetes from VS Code or GoLand. You can set breakpoints, step through code, and examine variables in the running process. You do not change the deployment, rebuild the image, or restart the pod.
The problem
Logs and metrics show what a service did. They do not show the state of the program at the moment of a bug. To use a debugger on a service in a cluster, you usually must do these steps:
- Add Delve to the container image.
- Change the container command to start the service under Delve.
- Expose the Delve port and deploy again.
Each deployment replaces the pod. A bug that depends on state, load, or timing is often gone after the restart. And the debug build must not stay in production.
What DebugHero does
DebugHero attaches Delve to the process that already runs:
- You select a pod by namespace and labels, in your IDE or with
debugctl. - DebugHero adds an ephemeral container with Delve to that pod. The pod does not restart.
- Delve attaches to your Go process. The process continues to run.
- DebugHero forwards the Delve port to your machine, and your IDE connects to it.
How it works explains each step.
What you need
| Requirement | Details |
|---|---|
| Your machine | Linux or macOS. |
| IDE | VS Code with the Go extension, or GoLand. You can also start sessions with the debugctl CLI. |
| Cluster | Kubernetes 1.25 or later. Your user must be allowed to add ephemeral containers, and the namespace must allow the SYS_PTRACE capability. See Cluster requirements. |
| Go binary | Built with debug information (DWARF). Binaries built with -ldflags="-s -w" do not work. |
| Account | A DebugHero account. debugctl login opens the sign-in page. |
Limitations
Know these limitations before you use DebugHero on a shared or production cluster:
- A breakpoint stops the process. While the process is stopped, it does not answer requests or health checks. If the liveness probe fails, the kubelet restarts the container, and the debug session ends.
- Go only. DebugHero uses Delve, the Go debugger.
- One pod for each session. If the labels select more than one pod, DebugHero uses the first pod in the list. Use labels that select exactly one pod.
- Nodes must be
linux/amd64. The debug image is not available for arm64 nodes yet. This includes minikube and kind on Apple-silicon Macs. - A stopped debug container stays in the pod spec. Kubernetes cannot remove an ephemeral container. When a session ends, its container stops, but it stays in the pod spec until the pod is replaced. You can start a new session on the same pod.
- Windows is not supported.
Next steps
- How it works: the components and the steps of a debug session.
- Cluster requirements: check that your cluster allows DebugHero.