Remote Debugging Applications on Openshift pods
In this post I would like to share my last challenge at work - remote debugging of an application running on Openhift. This method is also valid for Kubernetes pods.
Set up JMX
The first thing you have to do is to enable and configure JMX flags. Start your program with following parameters:
JMX use RMI for the communication between the JMX client and the remote JVM. That’s why I’ve set two ports. JMX client will connect to hostname - 127.0.0.1:3001. You probably wonder how it can work if there is no RMI server running on localhost. This is because the next step is to set up Openshift/Kubernetes port forwarding.
Port forwarding
Thanks to port forwarding feature you can forward one or more local ports to a pod. You need to be locally logged on the Openhift. If you do not have it yet - I recommend downloading OpenShift Client Tools (Windows, Linux) Use following command to start the proxy and forward ports to the remote pod:
Remember to replace
JVisualVM connection
If you have started proxy on the machine where you run JVisualVM, you can connect locally to RMI port: