I have two Kubernetes containers running in a pod, call them container A and B. A has a JMX server running. The Java options used to run the server are:
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.host=127.0.0.1
-Dcom.sun.management.jmxremote.port=1234
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.host=localhost
flag is set specifically so that JMX server isn't exposed to external clients.
Container B wants to monitor A using JMX over localhost only. The connection to JMX server in A is established using the following code:
String serverUrl = "service:jmx:rmi:///jndi/rmi://127.0.0.1:1234/jmxrmi";
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceUrl, null);
MBeanServerConnection mBeanConn = jmxConnector.getMBeanServerConnection();
I was expecting to code to run without any issues since I'm able to connect to JMX port of A from B using telnet. However, when the Java code runs, an exception is thrown, first few lines of which are:
java.rmi.ConnectException: Connection refused to host: 10.8.0.88; nested exception is:
java.net.ConnectException: Connection refused (Connection refused)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:623) ~[na:1.8.0_312]
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216) ~[na:1.8.0_312]
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202) ~[na:1.8.0_312]
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:132) ~[na:1.8.0_312]
The client is using the private IP to connect to RMI server instead of connecting using 127.0.0.1 and is failing as JMX server is listening only on localhost. I need help figuring out the best way to allow communication between containers A & B over localhost.