dockergokuberneteskubectldelve

kubectl logs displays only 'API server listening at: [::]:40000' when remote debugging with dlv is enabled - How do I get my logs back?


I currently have a go app that uses a lot fmt.printf. Whenever that app would run in a pod I was able to get the logs back by doing

kubectl logs podname

However I also needed to integrate remote debugging. I need to use dlv to allow my ide(GoLand) to remotely connect to the pod. It connects to the Pod at port 40000. Also when the Pods image runs it exposes port 40000 i.e the docker file has this in it 40000

I also have a service that looks like this in my minikube

apiVersion: v1
kind: Service
metadata:
  name: mydebug
spec:
  type: ClusterIP
  selector:
    app: fooapp
  ports:
  - protocol: TCP
    port: 40000
    targetPort: 40000
    name: delve

Now when I do kubectl logs podname I only get this back

API server listening at: [::]:40000
2022-10-30T21:18:57Z warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)

Is there anyway to get my logs back ? Ho


Solution

  • You can use the --continue exec flag, to continue the debugged process on the start, which then will lead to continued logs.

    So start delve e.g. with:

    dlv --listen=:2345 --headless exec your/app --continue
    

    Without the --continue flag, delve will wait for remote connections and halt your application. With the --continue flag, the application instead will start already.

    From dlv help exec:

    ...
    Usage:
      dlv exec <path/to/binary> [flags]
    
    Flags:
          --continue     Continue the debugged process on start.
    ...