<p>I'm trying to run jmx on ocp. I've set all required parameters in my container. When creating a container, I set the environment variables:</p>

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

<p>When I try to connect to my service (using service IP or hostname) - I get connection refused:</p>

<pre><code>IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: service.namespace-18569.svc
</code></pre>

<p>After a few attempts, I tried to check JMX endpoint using curl -I. </p>

<p>After checking in pod terminal (<code>curl -I 127.0.0.1:JMXPORT/Endpoint</code>) I get a response from the JMX server.</p>

<p>Unfortunately when I tried to use <code>curl -I</code> with service IP/Hostname (in the same pod terminal) - I get connection refused. </p>

<p>Is it possible to make a JMX connection between different pods using IP service?</p>

<p>EDIT:</p>

<p>My deployment config: </p>

<pre><code>apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  creationTimestamp: '2019-02-06T17:11:36Z'
  generation: 1
  labels:
    app: napeOfApp
  name: napeOfApp
  namespace: nameOfMynamespace
  resourceVersion: '202879946'
  selfLink: /apis/apps.openshift.io/v1/namespaces/nameOfMynamespace/deploymentconfigs/napeOfApp
  uid: 42606226-2a32-11e9-9b9a-02e3ccdc5484
spec:
  replicas: 1
  revisionHistoryLimit: 3
  selector:
    deploymentconfig: napeOfApp
  strategy:
    activeDeadlineSeconds: 21600
    resources: {}
    rollingParams:
      intervalSeconds: 1
      maxSurge: 25%
      maxUnavailable: 25%
      timeoutSeconds: 600
      updatePeriodSeconds: 1
    type: Rolling
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: napeOfApp
        deploymentconfig: napeOfApp
      name: napeOfApp
    spec:
      containers:
        - image: 'my image repo'
          imagePullPolicy: IfNotPresent
          name: napeOfApp
          ports:
            - containerPort: 8080
              protocol: TCP
            - containerPort: 3084  //(JMX PORT) 
              protocol: TCP
            - containerPort: 3104
              protocol: TCP
            - containerPort: 7005
              protocol: TCP
            - containerPort: 8443
              protocol: TCP
          resources:
            limits:
              cpu: '1'
              memory: 3584Mi
            requests:
              cpu: 500m
              memory: 2560Mi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
  test: false
  triggers:
    - type: ConfigChange
status:
  availableReplicas: 1
  conditions:
    - lastTransitionTime: '2019-02-06T17:11:41Z'
      lastUpdateTime: '2019-02-06T17:11:41Z'
      message: Deployment config has minimum availability.
      status: 'True'
      type: Available
    - lastTransitionTime: '2019-02-06T17:11:42Z'
      lastUpdateTime: '2019-02-06T17:11:42Z'
      message: replication controller "napeOfApp" successfully rolled out
      reason: NewReplicationControllerAvailable
      status: 'True'
      type: Progressing
  details:
    causes:
      - type: ConfigChange
    message: config change
  latestVersion: 1
  observedGeneration: 1
  readyReplicas: 1
  replicas: 1
  unavailableReplicas: 0
  updatedReplicas: 1
</code></pre>

<p>3084 is JMX port. </p>

michf
<blockquote>
  <p>Is it possible to make a JMX connection between different pods using IP service?</p>
</blockquote>

<p>Yes, it should work seamlessly, either using the service IP address or the service name according to how <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">DNS works in K8s</a>.</p>

<p>Looks like the problem for you is this:</p>

<pre><code>-Djava.rmi.server.hostname=127.0.0.1
</code></pre>

<p>This is basically binding to <code>127.0.0.1</code> only and allowing only local connections. You might want to try <code>0.0.0.0</code> so that external connections are allowed.</p>

<p>Hope it helps!</p>
