相同应用程序的多种服务:kubernetes中的端口 [英] Multiple services for same app:port in kubernetes
问题描述
我正在Kubernetes上尝试一种服务发现方案.我有20多种GRPC服务,可以将它们分组并部署为Kubernetes上的应用程序.每个应用程序通过一个通用的GRPC服务器提供其中一些服务.有一个发布该GRPC端口的服务,并且在那些服务上有标签,这些标签用于标识正在其中运行的GRPC服务器.
I am experimenting with a service discovery scheme on Kubernetes. I have 20+ GRPC services that can be grouped and deployed as applications on Kubernetes. Each application serves several of these services with a common GRPC server. There is a service to publish this GRPC port, and I have labels on those services that identify which GRPC servers are running there.
例如,我有一个服务于GRPC服务a,b,c的APP1应用程序. APP1的前面有一个连接到端口8000的服务,标签为a,b,c.因此,当集群中的某个组件需要连接到服务(例如"b")时,它将查找带有标签"b"的服务,并连接到其中一个的端口8000.这样,我可以用不同的方式对GRPC服务进行分组,进行部署,然后它们彼此找到.
For instance, I have APP1 application serving GRPC services a,b,c. There is a service in front of APP1 connected to the port 8000, with labels a,b,c. So when a component in the cluster needs to connect to service, say, "b", it looks up services that have the label "b", and connects to port 8000 of one of those. This way, I can group the GRPC services in different ways, deploy them, and they all find each other.
我开始考虑另一种方法.我希望为每个具有不同名称的同一个app:port
提供多个服务(每个GRPC服务一个服务),而不是为每个应用程序提供带有标签的服务.因此,在此新方案中,APP1将具有三个服务a,b和c,它们都连接到同一app:port.客户端只需查找名称"b"即可找到GRPC服务器"b".
I started thinking about an alternative approach. Instead of having one service with labels for each app, I want to have multiple services (one for each GRPC service) for the same app:port
with different names. So in this new scheme APP1 would have three services, a, b, and c, all connected to the same app:port. The clients would simply look up the name "b" to find the GRPC server "b".
问题是:您是否看到将具有不同名称的多个服务连接到同一应用程序的同一端口并暴露同一端口的任何潜在问题?也就是说,地址a:8000
,b:8000
,c:8000
都指向APP1:8000
.
The question is: do you see any potential problems with having multiple services with different names that are connected to the same port of the same app, exposing the same port? That is, addresses a:8000
, b:8000
, c:8000
all pointing to APP1:8000
.
推荐答案
老实说,只要您的应用程序内部识别出客户端正在尝试与a:8000
,b:8000
对话,我就不会出现任何问题.或c:8000
.本质上,在这种情况下,您只能在容器中找到单个端口8000
.这类似于每个服务的不同HTTP终结点,例如https://myendpoint:8000/a
,https://myendpoint:8000/b
和https://myendpoint/c
.
To be honest I don't see any problem as long as your application identifies internally that the client is trying to talk to either a:8000
, b:8000
, or c:8000
. Essentially, you will find to just a single port 8000
in this case in the container. This would be analogous to different HTTP endpoints per service some like https://myendpoint:8000/a
, https://myendpoint:8000/b
, and https://myendpoint/c
.
请注意,8000
是容器中的端口,但是Kubernetes将使用节点上的随机端口将流量转发到容器中的8000
.
Note that 8000
would be the port in the container but Kubernetes will use a random port on the node to forward the traffic to 8000
in the container.
这篇关于相同应用程序的多种服务:kubernetes中的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!