环境准备:1)搭建一个swarm mode集群环境
root@docker1:/home/docker/xu/swarm# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
2bjtayk2pbbcl384ef9dxvyi0 * docker1 Down Active Leader
b4f80o1a32afg5buim66w71se docker2 Down Active
2)创建一个基于overlay的mysql(名称)网络
root@docker1:/home/docker/xu/swarm# docker network ls
NETWORK ID NAME DRIVER SCOPE
1b1c3a449781 bridge bridge local
041a4a5c12d7 docker_gwbridge bridge local
a7c3520d5f74 host host local
10xf6wjdp7kc ingress overlay swarm
2t21vsd267ms mysql overlay swarm
a5b817842a3a none null local
1、Swarm mode有个内置的overlay网络ingress,该网络主要是用于swarm vip方式的负载均衡
root@docker1:/home/docker/xu/swarm# docker network ls
NETWORK ID NAME DRIVER SCOPE
1b1c3a449781 bridge bridge local
041a4a5c12d7 docker_gwbridge bridge local
a7c3520d5f74 host host local
10xf6wjdp7kc ingress overlay swarm
2t21vsd267ms mysql overlay swarm
a5b817842a3a none null local
2、Swarm mode vip负载均衡的官方解释
The swarm manager uses ingress load balancing to expose the services you want to make available externally to the swarm. The swarm manager can automatically assign the service a PublishedPort or you can configure a PublishedPort for the service. You can specify any unused port. If you do not specify a port, the swarm manager assigns the service a port in the 30000-32767 range.
External components, such as cloud load balancers, can access the service on the PublishedPort of any node in the cluster whether or not the node is currently running the task for the service. All nodes in the swarm route ingress connections to a running task instance.
3、Routing Mesh是实现vip负载均衡的关键技术, Routing Mesh的目的是每个主机上都为服务预留端口, 保证每台
机器上都可以访问到服务。实现的办法就是Ingress网络, 之前我们提到容器中会多出一块网络,我们Inspect ingress