生产环境部署swarm集群及 swarm-overlay-portainer(webui) 实战应用

参考文档:
调度过滤器:filter
调度策略:strategy
部署生产环境swarm集群
WEBUI portainer
Overlay 网络搭建

一、安装步骤
1. Set up a discovery backend :
10 上启动consul
docker run --restart=always -d -p 8500:8500 -h consul --name consul progrium/consul \
-server -bootstrap -advertise 172.19.9.10

2. Start the Swarm manager :
20/30 上启动manage01 manage02
docker run -d --restart=always --name swarm-manage01 -p 4000:4000 172.19.9.10:5000/swarm \
manage -H :4000 --replication --advertise 172.19.9.20:4000 consul://172.19.9.10:8500

docker run -d --restart=always --name=swarm-manage01 -p 4000:4000 172.19.9.10:5000/swarm \
manage -H :4000 --replication --advertise 172.19.9.30:4000 consul://172.19.9.10:8500

3. Connect to node01 and node02 in turn and join them to the cluster :
40/50 上启动node01 node02
docker run -d --restart=always --name=swarm-node01 172.19.9.10:5000/swarm \
join --advertise=172.19.9.40:2375 consul://172.19.9.10:8500

docker run -d --restart=always --name=swarm-node02 172.19.9.10:5000/swarm \
join --advertise=172.19.9.50:2375 consul://172.19.9.10:8500

4. 添加--label标签
40
#docker daemon --label region=huilongguan
vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --graph=/data1/docker -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 --cluster-store=consul://172.19.9.10:8500/network --cluster-advertise=em1:2375 --insecure-registry=172.19.9.10:5000 --label region=huilongguan
50
#docker daemon --label region=shangdi
vim /usr/lib/systemd/system/docker.service
ExecStart= ...... --label region=shangdi

二、测试结果
Node filters
Use a constraint filter

docker -H :4000 run -d --net=internaloverlay --name swarm-test-redis-0 -e constraint:node==server3.riskdetection 172.19.9.10:5000/redis
docker -H :4000 run -d --net=internaloverlay --name swarm-test-redis-1 -e constraint:node==server4.riskdetection 172.19.9.10:5000/redis
docker -H :4000 exec -ti swarm-test-redis-1 ping swarm-test-redis-0
PING swarm-test-redis-0 (10.10.10.10): 56 data bytes
64 bytes from 10.10.10.10: icmp_seq=0 ttl=64 time=1.261 ms
64 bytes from 10.10.10.10: icmp_seq=1 ttl=64 time=0.314 ms
64 bytes from 10.10.10.10: icmp_seq=2 ttl=64 time=0.292 ms
64 bytes from 10.10.10.10: icmp_seq=3 ttl=64 time=0.293 ms
64 bytes from 10.10.10.10: icmp_seq=4 ttl=64 time=0.284 ms
64 bytes from 10.10.10.10: icmp_seq=5 ttl=64 time=0.273 ms
64 bytes from 10.10.10.10: icmp_seq=6 ttl=64 time=0.259 ms

docker -H :4000 run -d --net=internaloverlay --name swarm-test-redis-hlg -e constraint:region==huilongguan 172.19.9.10:5000/redis
docker -H :4000 run -d --net=internaloverlay --name swarm-test-redis-sd -e constraint:region==shangdi 172.19.9.10:5000/redis
docker -H :4000 exec -ti swarm-test-redis-sd ping swarm-test-redis-hlg
PING swarm-test-redis-hlg (10.10.10.9): 56 data bytes
64 bytes from 10.10.10.9: icmp_seq=0 ttl=64 time=0.889 ms
64 bytes from 10.10.10.9: icmp_seq=1 ttl=64 time=0.268 ms
64 bytes from 10.10.10.9: icmp_seq=2 ttl=64 time=0.297 ms
64 bytes from 10.10.10.9: icmp_seq=3 ttl=64 time=0.254 ms
64 bytes from 10.10.10.9: icmp_seq=4 ttl=64 time=0.270 ms
64 bytes from 10.10.10.9: icmp_seq=5 ttl=64 time=0.283 ms
64 bytes from 10.10.10.9: icmp_seq=6 ttl=64 time=0.277 ms

docker -H :4000 ps | grep swarm-test
ea8cf21ae46f 172.19.9.10:5000/redis "docker-entrypoint.sh" 40 minutes ago Up 40 minutes
server3.riskdetection/swarm-test-redis-hlg c93c6054f5aa 172.19.9.10:5000/redis "docker-entrypoint.sh" 42 minutes ago Up 42 minutes
server4.riskdetection/swarm-test-redis-sd 24a092af0e45 172.19.9.10:5000/redis "docker-entrypoint.sh" About an hour ago Up 40 minutes
server3.riskdetection/swarm-test-redis-0 eda41c6d1b86 172.19.9.10:5000/redis "docker-entrypoint.sh" About an hour ago Up 41 minutes
server4.riskdetection/swarm-test-redis-1
小结:
通过overlay 不同主机间容器实现了互联,根据node,region分别将对应的容器分发到相应的node节点上。

三、注意:
Node filters除了 constraint 外,还有以下两种filter
Use the health filter
The node health filter prevents the scheduler from running containers on unhealthy nodes. A node is considered unhealthy if the node is down or it can’t communicate with the cluster store.

Use the containerslots filter
--label containerslots=3
Swarm will run up to 3 containers at this node, if all nodes are “full”, an error is thrown indicating no suitable node can be found. If the value is not castable to an integer number or is not present, there will be no limit on container number.

Container filters
affinity
dependency
port

四、安装管理界面WEBUI
docker run -d --restart=always --name portainer -p 9000:9000 portainer/portainer -H tcp://172.19.9.20:4000
设置密码,登陆
1.Cluster info
2.container 管理
3.images 管理
4.Network 管理
5.Volumes 管理
6.Swarm 集群管理


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值