k8s之SpringBoot远程调试

1. 修改Java程序的启动命令

修改dockerfile文件中的启动命令,重新部署服务到测试环境,记得在debug完成后,把这个参数再修改回来,不要带到线上环境

Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9997
http://ae01.alicdn.com/kf/Hb7bafee51225448583641ac72f77dc1di.png

2. 转发容器端口

本机需要安装kubectl工具-方法链接,配置rancher-cli工具-方法链接

edzdeMacBook-Pro:.kube edz$ rancher kubectl get pod
NAME                                READY   STATUS    RESTARTS   AGE
alarm-79688d9496-2fbqv              1/1     Running   1          2d
apollo-admin-79cbcfd878-f5qlg       1/1     Running   1          92d
apollo-config-69644d757d-clwc8      1/1     Running   0          13d
bell-78cd45df48-8l5xz               1/1     Running   0          2m41s
confucius-9f76dcf6c-8w2rc           1/1     Running   0          13m
kotler-67dd49f4dd-9fk9m             1/1     Running   0          2d5h
login-platform-77c56f9f99-hlj4j     1/1     Running   0          6m37s
middle-platform-bd7444f44-jvclg     1/1     Running   0          6m32s
operation-center-57bc5d99c7-zx76l   1/1     Running   0          27m
platon-5d45786f96-6pfhm             1/1     Running   0          4h9m
platon-6bcb4857bc-qdwwj             0/1     Running   0          35s
socrates-68bdb486fb-zqbnx           1/1     Running   0          15d
ui-platform-69ffc47b67-fj4qz        1/1     Running   0          6m9s
zipkin-7bbff796f9-kdxtt             1/1     Running   247        56d
edzdeMacBook-Pro:.kube edz$ rancher kubectl port-forward bell-78cd45df48-8l5xz  9997:9997
Forwarding from 127.0.0.1:9997 -> 9997
Forwarding from [::1]:9997 -> 9997
Handling connection for 9997
image

3. idea配置

最后一步最关键,需要保证服务端的代码和本地时一样的,请注意!

image

4. 结束语

祝大家早日解决bug!

你可能感兴趣的:(k8s之SpringBoot远程调试)