从 kubernetes pod 转发的 JMX 不同端口

JMX different port forward from kubernetes pod

我在将 jmx 从 kubernetes pod 转发到本地主机时遇到问题。 当端口转发到同一端口时一切正常:

kubectl port-forward ... 9010:9010 OR
kubectl port-forward ... 9010

但是,当我尝试转发到不同的本地端口时,

kubectl port-forward ... 9011:9010

jconsole 或 jms 都无法连接。

它阻止我同时分析多个应用程序。

JMS 错误:

com.oracle.jmc.rjmx.ConnectionException caused by java.rmi.NoSuchObjectException: no such object in table
    at com.oracle.jmc.rjmx.internal.RJMXConnection.connect(RJMXConnection.java:406)
    at com.oracle.jmc.rjmx.internal.ServerHandle.doConnect(ServerHandle.java:88)
    at com.oracle.jmc.rjmx.internal.ServerHandle.connect(ServerHandle.java:78)
    at com.oracle.jmc.console.ui.editor.internal.ConsoleEditor$ConnectJob.run(ConsoleEditor.java:73)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.rmi.NoSuchObjectException: no such object in table
    at java.rmi/sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:283)
    at java.rmi/sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:260)
    at java.rmi/sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)
    at java.management.rmi/javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source)
    at java.management.rmi/javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2105)
    at java.management.rmi/javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:321)
    at com.oracle.jmc.rjmx.internal.RJMXConnection.connectJmxConnector(RJMXConnection.java:451)
    at com.oracle.jmc.rjmx.internal.RJMXConnection.establishConnection(RJMXConnection.java:427)
    at com.oracle.jmc.rjmx.internal.RJMXConnection.connect(RJMXConnection.java:399)
    ... 4 more

jconsole 错误:

Connection to localhost:9011 did no succeed.

这是一个 RMI 问题。问题是交付给 JMX 客户端的 RMI 存根是为 9010 创建的,因此在尝试连接 9011 时失败。概述了几个不错的解决方案 here. Another option is to switch to JMXMP 这是一个纯套接字 JMX 协议,因此端口转发有效没有任何额外的解决方法。