Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker 诊断工具


IDEA 远程调试 Kubernetes 容器中的 Spring Boot 程序

IDEA Kubernetes Debug 大约 1152 字

远程 Debug 配置

IDEA中添加Remote JVM Debug配置项,拷贝以下配置。

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005

启动 Pod

--image-pull-policy:镜像拉取策略必须设置为Never,否则一直会卡在ImagePullBackOff状态。

--env:配置容器的环境变量,注意双引号。(JAVA_OPTS是自定义的环境变量,可参见文末Dockerfile

kubectl run myapp --image=docker.io/library/myapp:latest --image-pull-policy=Never --env="JAVA_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"

查看状态信息

kubectl describe pod myapp

端口映射

本地端口映射到Pod,此处映射了两个本地端口80805005Pod80805005

kubectl port-forward myapp 8080 5005

单个端口映射,本地10080端口映射到Pod8080端口。

kubectl port-forward myapp 10080:8080

输出

PS C:\> kubectl.exe port-forward myapp 8080 5005
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
Forwarding from 127.0.0.1:5005 -> 5005
Forwarding from [::1]:5005 -> 5005
Handling connection for 5005 # IDEA 开始 Debug 后会显示的处理连接
Handling connection for 8080 # 请求 8080 端口显示的处理连接

开始 Debug

容器启动后,IDEA开启Debug即可远程调试。

镜像 Dockerfile

FROM openjdk:11-oraclelinux8
WORKDIR /app
COPY target/test-0.0.1-SNAPSHOT.jar /app/app.jar
ENV JAVA_OPTS="-Xms10m -Xmx20m"
CMD ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar"]
阅读 1995 · 发布于 2022-06-08

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批