12

I want to profile my play application on my Kubernetes cluster.

I am using VisualVM, and the steps that I have taken are as follows:

  1. Image is built on ubuntu latest
  2. Running my play application with the following args:

    "-Dcom.sun.management.jmxremote",
    "-Dcom.sun.management.jmxremote.ssl=false",
    "-Dcom.sun.management.jmxremote.authenticate=false",
    "-Dcom.sun.management.jmxremote.port=1098"
    
  3. My Image has apt-get install -y visualvm

  4. I do kubectl port-forward <Container> 1098
  5. Open VisualVM, And I don't see the process.

I am not sure what I am doing wrong here. When running the application on localhost (not via IDE, straight from the startup script) everything works fine.

Update 1, deployment and service

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

Update 2 @marcospereira

File->Add JMX connection-> localhost:1098

Cannot connect to localhost:1098 using service jmx:rmi...

Gleeb
  • 10,773
  • 26
  • 92
  • 135

3 Answers3

5

It can be executed in the same form as QA below.

multiple app nodes how to expose jmx in kubernetes?

Please set java.rmi.server.hostname System Property.

"-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 connect to localhost:1098 .

I confirmed that I could connect.

Hiroki Matsumoto
  • 357
  • 4
  • 10
2

You have to add the rmi port option too -Dcom.sun.management.jmxremote.rmi.port=1098

Fabián
  • 51
  • 5
1

You need to run below command to port forward in a correct manner:

kubectl port-forward ${pod_name} 1098:1098

In visualvm, add jmx connection with localhost:1098.

Add below parameters to enable jmx connection in your java options,

  -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
chetan mahajan
  • 723
  • 7
  • 9