33

I'm working on a project to set up a cloud architecture using docker-swarm. I know that with swarm I could deploy replicas of a service which means multiple containers of that image will be running to serve requests.

I also read that docker has an internal load balancer that manages this request distribution.

However, I need help in understanding the following:

Say I have a container that exposes a service as a REST API or say its a web app. And If I have multiple containers (replicas) deployed in the swarm and I have other containers (running some apps) that talk to this HTTP/REST service.

Then, when I write those apps which IP:PORT combination do I use? Is it any of the worker node IP's running these services? Will doing so take care of distributing the load appropriately even amongst other workers/manager running the same service?

Or should I call the manager which in turn takes care of routing appropriately (even if the manager node does not have a container running this specific service)?

Thanks.

4

2 回答 2

33

当我编写这些应用程序时,我使用哪个 IP:PORT 组合?是否有任何工作节点 IP 运行这些服务?

您可以使用参与 swarm 的任何节点,即使该节点上不存在相关服务的副本。所以你将使用Node:HostPort组合。入口路由网格会将请求路由到活动容器。

一图胜万言

在此处输入图像描述

即使在运行相同服务的其他工作人员/经理之间,这样做是否会适当地分配负载?

默认情况下,入口控制器将执行循环。

现在客户端应该使用 dns round robin 来访问 docker swarm 节点上的服务。会出现经典的 DNS 缓存问题。为了避免这种情况,我们可以使用像 HAproxy 这样的外部负载均衡器。

在此处输入图像描述

于 2017-02-28T14:35:18.033 回答
0

现有答案的重要附加信息

在 docker swarm 前面使用代理 ( HAProxy ) 的优点是, swarm 节点可以驻留在代理服务器可访问但不可公开访问的私有网络上。这将使您的集群安全。

如果您正在使用AWS VPC,您可以创建一个私有子网并将您的 swarm 节点放置在私有子网中,并将代理服务器放置在可以将流量转发到 swarm 节点的公共子网中。

当您访问 HAProxy 负载均衡器时,它会将请求转发到集群中的节点。将swarm routing mesh请求路由到活动任务。如果由于任何原因 swarm 调度程序将任务分派到不同的节点,则无需重新配置负载均衡器。

有关更多详细信息,请阅读https://docs.docker.com/engine/swarm/ingress/

于 2021-04-11T16:35:26.590 回答