Docker swarm scaling behaviour on port mapping

徘徊边缘 提交于 2019-12-13 18:20:02

问题


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

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

From there, i can reach nginx on http://node01:8080

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

From there, i'm still able to reach nginx on http://node01: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?


回答1:


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

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'.




回答2:


You can reach any service (deployed with a stack) which exposes its port by using the IP of any machine in the swarm and that port. Docker swarm will then forward that request to one of the replicas. Which replica is decided by the healthstate (unhealthy services are ignored) and the load balancing option that is configured which by default is round robin.



来源:https://stackoverflow.com/questions/46407531/docker-swarm-scaling-behaviour-on-port-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!