【问题标题】:How can I open Openshift - port 9111 (grpc app)如何打开 Openshift - 端口 9111(grpc 应用程序)
【发布时间】:2020-07-02 16:30:48
【问题描述】:

我有 grpc 应用程序(客户端和服务器),它在 localhost 上运行良好,但我在 MiniShift 中遇到问题。每个应用程序在不同的 pod 中运行。问题是客户端无法连接到服务器:

java.net.ConnectException: finishConnect(..) failed: Connection refused
at io.grpc.netty.shaded.io.netty.channel.unix.Errors.throwConnectException(Errors.java:124) ~[grpc-netty-shaded-1.28.0.jar!/:1.28.0]
at io.grpc.netty.shaded.io.netty.channel.unix.Socket.finishConnect(Socket.java:243) ~[grpc-netty-shaded-1.28.0.jar!/:1.28.0]
at io.grpc.netty.shaded.io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.doFinishConnect(AbstractEpollChannel.java:672) ~[grpc-netty-shaded-1.28.0.jar!/:1.28.0]
at io.grpc.netty.shaded.io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.finishConnect(AbstractEpollChannel.java:649) ~[grpc-netty-shaded-1.28.0.jar!/:1.28.0]
at io.grpc.netty.shaded.io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:529) ~[grpc-netty-shaded-1.28.0.jar!/:1.28.0]
at io.grpc.netty.shaded.io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:465) ~[grpc-netty-shaded-1.28.0.jar!/:1.28.0]
at io.grpc.netty.shaded.io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378) ~[grpc-netty-shaded-1.28.0.jar!/:1.28.0]
at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[grpc-netty-shaded-1.28.0.jar!/:1.28.0]
at io.grpc.netty.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[grpc-netty-shaded-1.28.0.jar!/:1.28.0]
at io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[grpc-netty-shaded-1.28.0.jar!/:1.28.0]

在 java.lang.Thread.run(Thread.java:748) [na:1.8.0_242]

我尝试了 pod 之间的连接,但只打开了 80 和 443 端口。其余端口返回拒绝连接。

如何打开端口 9111(我的 grpc java 应用程序正在运行的地方)?谢谢

【问题讨论】:

    标签: java openshift grpc minishift


    【解决方案1】:

    我需要创建一个 NodePort 类型的 服务

    NodePorts 是一种服务类型,它在每台集群机器上打开一个端口,并且可以将流量 - TCP/UDP - 重定向到您的应用程序。为此,您需要 administration 权限并使用 system:admin 或授予您选择的用户...例如:

    oc adm policy add-cluster-role-to-user cluster-admin matko
    

    不幸的是,Openshift 基于 Kubernetes,Kubernetes 默认只允许节点端口在 30000-32767 范围内。

    您的应用程序仍会在 9111 中听到,但要从集群外部访问,我们只有我上面写的端口。

    找到应用服务并编辑:

    oc edit svc mysql
    

    然后,将 Type 更改为 NodePort 并选择一个端口 - 或随机获取一个:

    apiVersion: v1
    kind: Service
    metadata:
      name: mysql
      labels:
        name: mysql
    spec:
      type: NodePort
      ports:
        - port: 3036
          nodePort: 30036
          name: http
      selector:
        name: mysql
    

    这只是解释一次,切勿将数据库暴露在互联网上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 2015-10-30
      • 1970-01-01
      • 1970-01-01
      • 2012-10-28
      相关资源
      最近更新 更多