【问题标题】:Profiling Java application in kubernetes在 Kubernetes 中分析 Java 应用程序
【发布时间】:2017-06-02 21:02:31
【问题描述】:

我想在我的 Kubernetes 集群上分析我的 play 应用程序。

我正在使用VisualVM,我采取的步骤如下:

  1. 图像基于最新的 ubuntu 构建
  2. 使用以下参数运行我的 play 应用程序:

    "-Dcom.sun.management.jmxremote",
    "-Dcom.sun.management.jmxremote.ssl=false",
    "-Dcom.sun.management.jmxremote.authenticate=false",
    "-Dcom.sun.management.jmxremote.port=1098"
    
  3. 我的图片有apt-get install -y visualvm

  4. 我愿意kubectl port-forward <Container> 1098
  5. 打开 VisualVM,我看不到进程。

我不确定我在这里做错了什么。在 localhost 上运行应用程序时(不是通过 IDE,直接从启动脚本),一切正常。

更新 1、部署和服务

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: myApp
  labels:
    name: myApp
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      name: myApp
      labels:
        name: myApp
    spec:
      containers:
      - name: myApp
        image: ...
        args: ["-Dcom.sun.management.jmxremote", "-Dcom.sun.management.jmxremote.ssl=false", "-Dcom.sun.management.jmxremote.authenticate=false", "-Dcom.sun.management.jmxremote.port=1098"]
        ports:
        - containerPort: 9000
        env:
        ...
apiVersion: v1
kind: Service
metadata:
  name: myApp
  labels:
    name: myApp
spec:
  selector:
    name: myApp
  ports:
    - port: 80
      targetPort: 9000

更新 2 @marcospereira

文件->添加JMX连接-> localhost:1098

无法使用服务 jmx:rmi 连接到 localhost:1098...

【问题讨论】:

  • 你能添加你的部署和服务定义吗?
  • 那是因为,当你在本地运行时,visualvm 知道如何识别本地 Java 进程。您需要添加一个“JMX 连接”(文件 -> 添加 JMX 连接)。

标签: java docker profiling kubernetes


【解决方案1】:

可以和下面的QA一样执行。

multiple app nodes how to expose jmx in kubernetes?

请设置java.rmi.server.hostname系统属性。

"-Dcom.sun.management.jmxremote",
"-Dcom.sun.management.jmxremote.ssl=false",
"-Dcom.sun.management.jmxremote.authenticate=false",
"-Dcom.sun.management.jmxremote.port=1098"
"-Djava.rmi.server.hostname=127.0.0.1" #add

Jmx 连接到localhost:1098

我确认可以连接。

【讨论】:

    【解决方案2】:

    您也必须添加 rmi 端口选项 -Dcom.sun.management.jmxremote.rmi.port=1098

    【讨论】:

      【解决方案3】:

      您需要运行以下命令以正确方式进行端口转发:

      kubectl 端口转发 ${pod_name} 1098:1098

      在visualvm中,添加jmx与localhost:1098的连接。

      添加以下参数以在您的 java 选项中启用 jmx 连接,

        -Dcom.sun.management.jmxremote
        -Dcom.sun.management.jmxremote.port=1098
        -Dcom.sun.management.jmxremote.rmi.port=1098
        -Dcom.sun.management.jmxremote.authenticate=false
        -Dcom.sun.management.jmxremote.ssl=false
        -Djava.rmi.server.hostname=127.0.0.1
      

      【讨论】:

        猜你喜欢
        • 2011-11-26
        • 1970-01-01
        • 1970-01-01
        • 2011-08-10
        • 2011-02-09
        • 1970-01-01
        • 2011-01-29
        • 2011-01-07
        • 1970-01-01
        相关资源
        最近更新 更多