简体   繁体   English

连接到在不同 pod 上运行的 gRPC 服务器

[英]Connect to gRPC server running on different pod

I have a gRPC client and server running on my local and I'm able to communicate over them via HTTP2 through localhost.我有一个 gRPC 客户端和服务器在我的本地运行,我可以通过 localhost 通过 HTTP2 通过它们进行通信。 But when the apps are deployed in dev environment using Kubernetes and Docker, I'm not able to call the gRPC server from client app.但是,当使用 Kubernetes 和 Docker 在开发环境中部署应用程序时,我无法从客户端应用程序调用 gRPC 服务器。

I connect to the client using this code:我使用以下代码连接到客户端:

ManagedChannel managedChannel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build();

In DEV: Here is my application.yml from server app.在 DEV 中:这是我来自服务器应用程序的 application.yml。

grpc:
  port: 6565
  enabled: true

I have the gRPC server running on port 6565, so I have changed the following on client application.yml as well我的 gRPC 服务器在端口 6565 上运行,所以我也在客户端 application.yml 上更改了以下内容

taxgRPC:
  host: bpstax-ws.g-dev4.svc.rnq.k8s.copart.com
  port: 6565  

When my client calls the server, the server doesn't get any incoming requests and client fails giving the following exception:当我的客户端调用服务器时,服务器没有收到任何传入请求,客户端失败并给出以下异常:

Caused by: io.grpc.netty.shaded.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: bpstax-ws.g-dev4.svc.rnq.k8s.copart.com/10.148.2.194:6565

When I log into the particular dev pod, I can see the port listening to the gRPC server.当我登录到特定的开发 pod 时,我可以看到正在侦听 gRPC 服务器的端口。

[dedas@rndcks401 ~]$ kubectl exec -ti bpstax-g-dev4-v029-74mj2 -n g-dev4 -- bash
bash-4.1$ netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:6565                0.0.0.0:*                   LISTEN      1/java
tcp        0      0 0.0.0.0:38957               0.0.0.0:*                   LISTEN      1/java
tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN      1/java
tcp        0      0 0.0.0.0:8081                0.0.0.0:*                   LISTEN      1/java

I need some help on how to connect to this gRPC server.我需要一些关于如何连接到这个 gRPC 服务器的帮助。 Please let me know if any clarifications/code is required.如果需要任何说明/代码,请告诉我。

I guess you have to provide a correct host to your gRPC client.我想您必须为您的 gRPC 客户端提供正确的主机。 Within your k8s env the best way to discover you server pod's ip address is though headless service .在您的 k8s 环境中,发现服务器 pod 的 ip 地址的最佳方法是headless service

The example definition:示例定义:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: server
  name: server-headless
  namespace: <YOUR_NAMESPACE>
spec:
  clusterIP: None
  ports:
  - name: tcp
    port: 6565
    protocol: TCP
    targetPort: 6565
  selector:
    app: <SERVER_POD_LABEL>
  type: ClusterIP

Having the headless service for your server app you can use service's FQDN as a host.为您的服务器应用程序提供无头服务,您可以使用服务的 FQDN 作为主机。 This way you can be sure the service's FQDN is always resolved to the correct pod's ip/s.这样您就可以确保服务的 FQDN 始终解析为正确的 pod 的 ip/s。

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

相关问题 无法将grpc客户端连接到grpc服务器 - Unable to connect grpc client to grpc server 如何连接到运行Java服务器的另一台计算机? - How to connect to a different computer running a Java server? 无法连接到grpc服务器,获取“第一个收到的帧未设置” - not able to connect to grpc server getting 'First received frame was not SETTINGS' 无法通过SSL从客户端连接到grpc服务器 - Not able to connect to grpc server from client through SSL 即使对于不同的请求 grpc,方法也会继续运行并发送相同的信息 - Method keeps running and sending the same information even for different request grpc 在模拟器上运行 andoid 应用程序时出现 GRPC 服务器错误 - GRPC Server error while running andoid app on emulator 连接到在Eclipse中运行的服务器套接字 - connect to server socket running in eclipse 如何使用 IP 地址和端口号连接到服务器套接字? (客户端运行在与服务器不同的机器上) - How do I connect to the server socket using the ip address and port number? (client is running on a different machine than server) 无法通过SSL从客户端使用还原代理(HAProxy)连接到gRPC服务器 - Not able to connect to gRPC Server with revert proxy (HAProxy) from client through SSL 编译GRPC服务器/客户端 - Compiling GRPC server/client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM