Skip to main content

Cluster requirements

DebugHero adds an ephemeral container with Delve to your pod. Your cluster, your permissions, and your Go binary must allow this. Do the checks on this page before your first session.

Summary​

RequirementValue
Kubernetes1.25 or later
Nodeslinux/amd64
Permissionslist and get pods; update on pods/ephemeralcontainers; create on pods/portforward
Pod Security AdmissionThe namespace must allow the SYS_PTRACE capability: level privileged, or an exemption
Image pullThe nodes can pull docker.io/madhavhugar/debughero:0.0.9
Go binaryBuilt with Go 1.22 to 1.25, with debug information (DWARF)

Kubernetes version​

Ephemeral containers are stable in Kubernetes 1.25 and later. To see the server version, run:

shell
kubectl version

Nodes​

The debug image is available only for linux/amd64. Pods on arm64 nodes cannot be debugged yet. This includes AWS Graviton nodes, and minikube or kind on Apple-silicon Macs.

To see the architecture of the node that runs your pod, run:

shell
kubectl get node "$(kubectl get pod <pod> -n <namespace> -o jsonpath='{.spec.nodeName}')" \
-o jsonpath='{.status.nodeInfo.architecture}'

Permissions​

debugd uses your kubeconfig (the --kubeconfig flag, else KUBECONFIG, else ~/.kube/config). Your user, or the group of your user, must have these permissions in the namespace of the target pod:

ResourceVerbsWhy
podsget, listFind the pod by labels, and watch the debug container.
pods/ephemeralcontainersupdateAdd the debug container to the pod.
pods/portforwardcreateForward the Delve port to your machine.

To check your permissions, run these commands. Each command must print yes.

shell
kubectl auth can-i list pods -n <namespace>
kubectl auth can-i get pods -n <namespace>
kubectl auth can-i update pods --subresource=ephemeralcontainers -n <namespace>
kubectl auth can-i create pods --subresource=portforward -n <namespace>

Use the --subresource flag. kubectl reads pods/portforward as a pod with the name portforward, so that form gives a wrong result.

If a command prints no, ask your cluster admin to give you a role with these rules:

debughero-role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: debughero
namespace: <namespace>
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list"]
- apiGroups: [""]
resources: ["pods/ephemeralcontainers"]
verbs: ["update"]
- apiGroups: [""]
resources: ["pods/portforward"]
verbs: ["create"]
warning

pods/ephemeralcontainers gives a user control of the processes in a pod. Give this role only for the namespaces and the users that need it.

Admission policies​

The debug container needs these settings, so that Delve can attach to your process:

  • the SYS_PTRACE capability,
  • runAsUser: 0,
  • allowPrivilegeEscalation: true.

Admission controllers check ephemeral containers the same as other containers. They can reject the debug container.

Pod Security Admission​

Namespace level (pod-security.kubernetes.io/enforce)Result
privilegedThe debug container is allowed.
No labelThe cluster default applies. It is privileged, unless the admin set another default in the API server configuration.
baselineRejected. SYS_PTRACE is not in the allowed capabilities.
restrictedRejected. The container runs as root and adds a capability.

To see the level of a namespace, run:

shell
kubectl get namespace <namespace> -o jsonpath='{.metadata.labels}'

If the namespace uses baseline or restricted, a cluster admin must allow the debug container. For example, the admin can set the namespace to privileged, or add an exemption in the Pod Security Admission configuration of the API server.

Kyverno and OPA Gatekeeper​

Policies that block added capabilities, root users, or privilege escalation also reject the debug container. Examples are the Kyverno disallow-capabilities policy and the Gatekeeper K8sPSPCapabilities template. Ask your cluster admin for an exception for ephemeral containers with names that start with debughero-.

Image pull​

The nodes must pull the debug image docker.io/madhavhugar/debughero:0.0.9 from Docker Hub. If your cluster allows images only from approved registries, ask your admin to approve the image, or to copy it to an approved registry.

Go binary​

Go version​

The debug image contains Delve 1.25. Delve 1.25 supports binaries built with Go 1.22 to Go 1.25. Delve does not attach to binaries built with a newer Go version. Support for newer Go versions is in progress.

To see the Go version of your binary, run:

shell
go version <path-to-binary>

Debug information​

Delve needs the DWARF debug information in the binary.

Build flagsResult
Default go buildWorks. The compiler optimizes the code, so some variables can show as "optimized away", and stepping can skip lines.
-gcflags="all=-N -l"Best result. No optimizations and no inlining. Use it for images that you plan to debug.
-ldflags="-s -w"Does not work. The debug information is removed.
-trimpathDelve works, but DebugHero cannot find the build directory, because the binary has no absolute paths. You must map the source paths yourself. See Map source paths.

Next steps​