繁体   English   中英

Openshift中Pod之间的JMX连接

[英]JMX connection between pods in Openshift

我正在尝试在ocp上运行jmx。 我已经在容器中设置了所有必需的参数。 创建容器时,我设置了环境变量:

-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

当我尝试连接到我的服务时(使用服务IP或主机名)-我被拒绝连接:

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

经过几次尝试后,我尝试使用curl -I检查JMX端点。

签入Pod终端( curl -I 127.0.0.1:JMXPORT/Endpoint )后,我收到了JMX服务器的响应。

不幸的是,当我尝试使用带有服务IP /主机名的curl -I (在同一pod终端中)时,我得到连接被拒绝。

是否可以使用IP服务在不同的Pod之间建立JMX连接?

编辑:

我的部署配置:

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

3084是JMX端口。

是否可以使用IP服务在不同的Pod之间建立JMX连接?

是的,它应该根据DNS在K8s中的工作方式,使用服务IP地址或服务名称来无缝运行

看来您遇到的问题是这样的:

-Djava.rmi.server.hostname=127.0.0.1

这基本上仅绑定到127.0.0.1 ,并且仅允许本地连接。 您可能想尝试0.0.0.0以便允许外部连接。

希望能帮助到你!

我猜,如果您看到连接被拒绝的错误,则说明服务端口是错误的。 原因是“连接被拒绝”本身意味着该端口甚至根本没有打开。

因此,您可能只是试图在错误的IP上访问服务。

例如,当您尝试访问主机IP上的服务端口时,就会发生这种情况。 请记住,服务端口在群集内部 ,而主机端口会将该端口暴露在(通常为5位数)端口上。

要弄清楚,请oc get svc -o wide并查看服务绑定到的节点端口。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM