Docker Swarm集群中部署Traefik负载均衡器

  

一、创建单节点的Docker Swarm集群

docker swarm init

 

二、在Swarm集群中创建一个网络

docker network create --driver=overlay traefik --attachable

 

三、在Swarm集群中部署traefik负载均衡器服务

docker service create \

--name traefik \

--constraint=node.role==manager \

--publish 80:80 --publish 8080:8080 \

--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \

--network traefik \

traefik \

--docker \

--docker.swarmmode \

--docker.domain=traefik \

--docker.watch \

--web

 

四、在Swarm集群中分别部署2个容器服务(httpdnginx

#2.1 httpd.abc.com

docker service create \

--name httpd \

--network traefik \

--label "traefik.backend=httpd" \

--label "traefik.enable=true" \

--label "traefik.protocol=http" \

--label "traefik.port=80" \

--label "traefik.frontend.rule=Host:httpd.abc.com" \

httpd

 

#2.2 nginx.abc.com

docker service create \

--name nginx \

--network traefik \

--label "traefik.backend=nginx" \

--label "traefik.enable=true" \

--label "traefik.protocol=http" \

--label "traefik.port=80" \

--label "traefik.frontend.rule=Host:nginx.abc.com" \

nginx

 

 

五、在浏览器中通过域名访问2个网站、查看Traefik UI

#修改Win7客户端电脑的hosts文件C:\Windows\System32\drivers\etc\hosts

#增加2条主机记录:

httpd.abc.com 192.168.3.168

nginx.abc.com 192.168.3.168

 

http://192.168.3.168:8080

http://httpd.abc.com

http://nginx.abc.com

 

 

六、Swarm集群中服务扩容后,再查看Traefik UI

docker service scale httpd=2

docker service scale nginx=3

 

http://192.168.3.168:8080

 

附图:

 

01-创建单节点的Docker Swarm集群.jpg

02-创建traefik overlay网络.jpg

03-创建traefik服务.jpg

04-创建nginx和httpd服务.jpg

05-查看traefik UI.jpg

06-分别扩容2个服务.jpg

07-查看traefik UI.jpg

参考链接:

docker swarm模式使用traefik部署服务

http://blog.51cto.com/6764097/2066670

 

Docker Swarm (mode) cluster

http://docs.traefik.cn/user-guide/swarm-mode

 


猜你喜欢

转载自blog.51cto.com/10321203/2318481
今日推荐