1.为应用开启JDWP调试端口
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:容器debug端口
2.使用 kubectl port-forward 转发端口
kubectl port-forward pod/<your-pod-name> 本地端口:容器debug端口
3.在IDE中配置Remote JVM Debug
-
在IntelliJ IDEA中,创建或编辑一个 Remote JVM Debug 类型的运行配置。
-
将 Debugger mode 设置为
Attach to remote JVM。 -
将 Host 设置为
localhost,Port 设置为5005。 -
保存配置并点击Debug按钮,如果控制台显示
Connected to the target VM,则表示连接成功。