App Running in Kubernetes Cluster

To forward JMX port from K8 pod to your local PC with kubectl port-forward.


Add following JVM options to your app:

-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


The critical part here is that:

  • The same port should be used as 'jmxremote.port' and 'jmxremote.rmi.port'. This is needed to forward one port only.

  • 127.0.0.1 should be passed as rmi server hostname. This is needed for JMX connection to work via port-forwarding.


Forward the JMX port (1099) to your local PC via kubectl:

kubectl port-forward <your-app-pod> 1099

Open jconsole connection to your local port 1099:

jconsole 127.0.0.1:1099

This way makes it possible to debug any Java pod via JMX without having to publicly expose JMX via K8 service (which is better from security perspective).

User Interfaces

JConsole


Visual VM

https://visualvm.github.io/



  • No labels