<p>I am trying to connect to a JMX port that I have defined to be 1099 (as is the default) on my Java application (Java 8 and with Spring Boot 1.4 and Tomcat) using a client such as JConsole, Java Mission Control, or Java VisualVM, but I am reaching an error: </p>

<pre><code>java.rmi.ConnectException: Connection refused to host: 10.xxx.xxx.xx, nested exception is:
     java.net.ConnectException: Connection timed out
     ...
</code></pre>

<p>Note that I hid the exact host IP, but it is the pod IP of the particular Kubernetes-managed Docker container that my service is deployed in. I try to connect to the JMX port using the following service URL:</p>

<pre><code>jconsole service:jmx:rmi://&lt;nodeIP&gt;:&lt;nodePort&gt;/jndi/rmi://&lt;nodeIP&gt;:&lt;nodePort&gt;/jmxrmi 
</code></pre>

<p>I know that JMX opens a <a href="https://stackoverflow.com/questions/7163173/jmx-enabled-java-application-appears-to-open-a-random-high-order-port-when-jmx-c">random high port</a>, and I have tried to resolve that by including a <a href="https://stackoverflow.com/a/33089641">custom @Configuration class that forces that high port to also serve on port 1099</a>. I have gone into the actual container and pod and ran </p>

<pre><code>netstat -tulpn
</code></pre>

<p>to see the ports that are opened, and I have confirmed that the only ports opened are 8443 (which my application is running on) and 1099 (the JMX port); this indicates that my class works. I also ensured that port 1099 is open on the Kubernetes side, so that is not what is blocking it.</p>

<p>As many answers surrounding a JMX remote connection have suggested, I have tried many variations of the following Java options to no avail:</p>

<pre><code>-Dcom.sun.management.jmxremote  -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.jmi.port=1099 -Djava.rmi.server.hostname=0.0.0.0
</code></pre>

<p>The answers have suggested forcing the JMX port and the RMI registry port to be the same, but none of these have worked. </p>

<p>I believe the issue may be because the hostname (as I tried to make dynamic with -Djava.rmi.server.hostname=0.0.0.0) can not resolve to the different hostnames (pod IPs) that are created every time my service is deployed. </p>

<p>Thus, it looks like the connection cannot complete because JMX is unable to see what hostname Kubernetes is assigning after my service is deployed. </p>

<p>Is there a way for JMX to recognize the Kubernetes hostname? Or, is there some other way to connect remotely to a JMX port through a Kubernetes-deployed service?</p>

<p><strong>EDIT 1:</strong> I have done some additional research, and maybe an optional JMXMP instead of RMI may work? Has anyone gotten this working with Tomcat?</p>

<p>The, jmx remote connection is a pain to work with, proxying it is impossible from my view. I had similar problems and in the end I just used jolokia to connect.</p>

<p>Jolokia is a JMX-HTTP bridge giving an alternative to JSR-160 connectors. It is an agent based approach with support for many platforms. In addition to basic JMX operations it enhances JMX remoting with unique features like bulk requests and fine grained security policies. -> <a href="http://jolokia.org" rel="nofollow noreferrer">http://jolokia.org</a></p>
