Search code examples
kubernetesadoptopenjdkopenj9

JMX Connection refused on Kubernetes with AdoptOpenJDK OpenJ9


With my team we are trying to move our micro-services to openj9, they are running on kubernetes. However, we encounter a problem on the configuration of JMX. (openjdk8-openj9) We have a connection refused when we try a connection with jvisualvm (and a port-forwarding with Kubernetes). We haven't changed our configuration, except for switching from Hotspot to OpenJ9.

The error :

E0312 17:09:46.286374   17160 portforward.go:400] an error occurred forwarding 1099 -> 1099: error forwarding port 1099 to pod XXXXXXX, uid : exit status 1: 2020/03/12 16:09:45 socat[31284] E connect(5, AF=2 127.0.0.1:1099, 16): Connection refused

The java options that we use :

-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.local.only=false 
-Dcom.sun.management.jmxremote.port=1099 
-Dcom.sun.management.jmxremote.rmi.port=1099

We are using the last adoptopenjdk/openjdk8-openj9 docker image. Do you have any ideas?

Thank you !

Regards.


Solution

  • I managed to figure out why it wasn't working. It turns out that to pass the JMX options to the service we were using the Kubernetes service descriptor in YAML. It looks like this:

      - name: _JAVA_OPTIONS
            value:  -Dzipkinserver.listOfServers=http://zipkin:9411 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.rmi.port=1099
    

    I realized that the JMX properties were not taken into account from _JAVA_OPTIONS when the application is not launch with ENTRYPOINT in the docker container. So I pass the properties directly into the Dockerfile like this and it works.

    CMD ["java", "-Dcom.sun.management.jmxremote", "-Dcom.sun.management.jmxremote.authenticate=false", "-Dcom.sun.management.jmxremote.ssl=false", "-Dcom.sun.management.jmxremote.local.only=false", "-Dcom.sun.management.jmxremote.port=1099", "-Dcom.sun.management.jmxremote.rmi.port=1099", "-Djava.rmi.server.hostname=127.0.0.1", "-cp","app:app/lib/*","OurMainClass"]
    

    It's also possible to keep _JAVA_OPTIONS and setup an ENTRYPOINT in the dockerfile.

    Thanks!