英文:
kubectl logs displays only 'API server listening at: [::]:40000' when remote debugging with dlv is enabled - How do I get my logs back?
问题
我目前有一个使用了很多fmt.printf
的Go应用程序。每当该应用程序在Pod中运行时,我可以通过执行kubectl logs podname
来获取日志。
然而,我还需要集成远程调试。我需要使用dlv
来允许我的IDE(GoLand)远程连接到该Pod。它连接到Pod的端口40000。此外,当Pod的镜像运行时,它会暴露端口40000,即Docker文件中包含了这个端口。
我还在我的minikube中有一个如下所示的服务:
apiVersion: v1
kind: Service
metadata:
name: mydebug
spec:
type: ClusterIP
selector:
app: fooapp
ports:
- protocol: TCP
port: 40000
targetPort: 40000
name: delve
现在,当我执行kubectl logs podname
时,我只会得到以下输出:
API server listening at: [::]:40000
2022-10-30T21:18:57Z warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
有没有办法获取我的日志?
英文:
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
答案1
得分: 1
你可以使用--continue
执行标志,在启动时继续调试的进程,这将导致日志的持续输出。
例如,使用以下命令启动 delve:
dlv --listen=:2345 --headless exec your/app --continue
如果没有使用--continue
标志,delve将等待远程连接并暂停你的应用程序。使用--continue
标志,应用程序将立即开始运行。
根据dlv help exec
的说明:
...
用法:
dlv exec <path/to/binary> [flags]
标志:
--continue 在启动时继续调试的进程。
...
英文:
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.
...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论