本文介绍了Docker群在端口映射上的扩展行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由三个节点组成的群:

I have a swarm composed of three nodes:

$ sudo docker node ls
ID                            HOSTNAME         STATUS              AVAILABILITY        MANAGER STATUS
i12s3zxsn4vu1c98bv3i5idr8     node03           Ready               Active
i2ckxvsju4tmommxim3dbfq7l     node02           Ready               Active
wak4isl46dn7pbo39drrhphju *   node01           Ready               Active              Leader

然后,我在该群集上运行1个nginx副本,并将其端口映射到8080:

Then I run 1 replica of nginx on that swarm and map his port to 8080:

$ sudo docker service create --replicas 1 --publish 8080:80 --name nginx nginx
$ sudo docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
neahnb9mvi1i        nginx               replicated          1/1                 nginx:latest        *:8080->80/tcp

从那里,我可以通过 http://node01:8080

接下来,我将nginx实例缩放为6:

Next, I scale nginx instances to 6:

$ sudo docker service scale nginx=6
$ sudo docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
neahnb9mvi1i        nginx               replicated          6/6                 nginx:latest        *:8080->80/tcp

从那里,我仍然可以通过 http://node01:8080 到达nginx.

From there, i'm still able to reach nginx on http://node01:8080.

但是,如果docker swarm将多个节点作为唯一主机公开,那么在我的所有nginx服务都映射到相同的8080端口时,他如何在扩展操作期间管理端口?在内部由群集完成并返回8080答案的所有服务实例之间是否存在循环负载平衡?

However, if docker swarm expose several node as a unique host, how does he manage the port during such a scaling operation as all my nginx services are mapped on the same 8080 port? Is there a round robin load balancing between all services instances done by swarm internally and returning the answer on 8080?

推荐答案

我相信对主机的请求将以循环类型分配的方式分配.

I believe the requests to the hosts get assigned in a round-robin type assignment.

找到了关于此的便捷文章 http://blog.scottlogic.com/2016/08/30/docker-1-12-swarm-mode-round-robin.html .检出标题为" INGRESS AND ROUND ROBIN LOAD BALANCING "的零件.

Found this handy article about it http://blog.scottlogic.com/2016/08/30/docker-1-12-swarm-mode-round-robin.html . Checkout the part titled 'INGRESS AND ROUND ROBIN LOAD BALANCING'.

这篇关于Docker群在端口映射上的扩展行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 02:26