Recently at work, I have struggled to find a way to connect through JVisualVM (an excellent JMX performance visualizer for the JVM) to
an Openshift pod. What I will say is however also valid for Kubernetes pods in general (using
kubectl port-forward), or for running jconsole on Linux.
Sadly, the handy method I have previously used with nodeports will not work here because of problems with the internal hostname used with JMX arguments.
So first of all, I of course started with the usual JVM flags to enable JMX:
As usual, you get to pick which port to use for JMX and RMI, as long as you set both to be the same. Now for the hostname. You should set up 127.0.0.1. This is because the next step is to set up port forwarding, so the JVM will see the connection as coming locally.
Go to some machine (ideally the one you’ll run JVisualVM on) and execute:
oc login #login to Openshift
If you have executed this on the machine where you run JVisualVM, you can now connect locally to
RMI_PORT. Otherwise, you’ll have an additional step of opening a SOCKS proxy to that machine.
You can do that with PuTTy on Windows, or with
ssh -D on Linux. Then you can connect, again locally, to