副本集中所有Pod之间的消息传递 [英] Message-passing between all pods in a replica set

查看:58
本文介绍了副本集中所有Pod之间的消息传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个要部署到Kubernetes的应用程序,我希望每个Pod都可以容纳在其中 与副本集中所有其他Pod的TCP连接,因此任何容器都可以通知另一个 某些用例中的容器.如果添加了Pod,则应在Pod和所有Pod之间创建新的连接 副本集中的其他Pod.

如何从给定的Pod中打开与所有其他Pod的TCP连接?即,我如何发现所有 他们的IP地址?

我有一个ClusterIP服务DNS名称,该名称通过选择器指向这些容器. 到目前为止,我已经考虑过尝试使用.例如,在 循环,每次通过连接请求一个容器ID,至少在我至少说一遍后暂停 每个容器ID的三个连接.然后大约每分钟重复一次,以获取新的Pod 已添加.可以使用keepalive删除与已消失的Pod的连接.

有更好的方法吗?

如果有关系,我将使用Go编写此应用程序.

解决方案

如果pod之间提到的通讯不是此应用程序的主要功能,而是该应用程序需要此功能,则强烈建议您不要重新发明并使用第3方组件.

Redis 看起来很不错,尤其是转到.通过其 Helm图表,也非常容易部署到Kubernetes. >

I'm writing an application to be deployed to Kubernetes where I want each pod to hold a TCP connection to all the other pods in the replica set so any container can notify the other containers in some use case. If a pod is added, a new connection should be created between it and all the other pods in the replica set.

From a given pod, how do I open a TCP connection to all the other pods? I.e., how do I discover all their IP addresses?

I have a ClusterIP Service DNS name that points to these pods by selector, and that's the mechanism I've thought of trying to use so far. E.g., open a TCP connection to that DNS name repeatedly in a loop, requesting a container ID over the connection each time, pausing when I've gotten say at least three connections for each container ID. Then repeating that every minute or so to get new pods that have been added. A keepalive could be used to remove connections to pods that have gone away.

Is there a better way to do it?

If it matters, I'm writing this application in Go.

解决方案

If the mentioned communication between the pods is not the main functionality of this application, but rather the application requires this functionality, I would strongly suggest not re-inventing the wheel and use a 3rd party component.

Redis looks like a very good candidate, in particular Pub/Sub mechanism of Redis.

So, all of the pods will subscribe to a certain channel in Redis, and when a pod wants to notify others, it will simply publish a message on the same channel.

Redis has client libraries in many languages including Go. Also very easy to deploy to Kubernetes via its Helm chart.

这篇关于副本集中所有Pod之间的消息传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆