赞
踩
个人主页:征服bug-CSDN博客
kubernetes专栏:云原生_征服bug的博客-CSDN博客
目录
Docker Swarm 是 Docker 的集群管理工具。它将 Docker 主机池转变为单个虚拟 Docker 主机,使得容器可以组成跨主机的子网网络。Docker Swarm 提供了标准的 Docker API,所有任何已经与 Docker 守护程序通信的工具都可以使用 Swarm 轻松地扩展到多个主机。
集群的管理和编排是使用嵌入到 docker 引擎的 SwarmKit,可以在 docker 初始化时启动 swarm 模式或者加入已存在的 swarm。
任何规模都有高性能表现
对于企业级的 Docker Engine 集群和容器调度而言,可拓展性是关键。任何规模的公司——不论是拥有五个还是上千个服务器——都能在其环境下有效使用 Swarm。
经过测试,Swarm 可拓展性的极限是在 1000 个节点上运行 50000 个部署容器,每个容器的启动时间为亚秒级,同时性能无减损。
灵活的容器调度
Swarm 帮助 IT 运维团队在有限条件下将性能表现和资源利用最优化。Swarm 的内置调度器(scheduler)支持多种过滤器,包括:节点标签,亲和性和多种容器部策略如 binpack、spread、random 等等。
服务的持续可用性
Docker Swarm 由 Swarm Manager 提供高可用性,通过创建多个 Swarm master 节点和制定主 master 节点宕机时的备选策略。如果一个 master 节点宕机,那么一个 slave 节点就会被升格为 master 节点,直到原来的 master 节点恢复正常。
此外,如果某个节点无法加入集群,Swarm 会继续尝试加入,并提供错误警报和日志。在节点出错时,Swarm 现在可以尝试把容器重新调度到正常的节点上去。
和 Docker API 及整合支持的兼容性
Swarm 对 Docker API 完全支持,这意味着它能为使用不同 Docker 工具(如 Docker CLI,Compose,Trusted Registry,Hub 和 UCP)的用户提供无缝衔接的使用体验。
Docker Swarm 为 Docker 化应用的核心功能(诸如多主机网络和存储卷管理)提供原生支持
开发的 Compose 文件能(通过 docker-compose up )轻易地部署到测试服务器或 Swarm 集群上。Docker Swarm 还可以从 Docker Trusted Registry 或 Hub 里 pull 并 run 镜像。
集群模式,当修改了服务的配置后无需手动重启服务。并且只有集群中的manager才能管理集群中的一切(包括服务、容器都归它管,在一个woker节点上无法操作容器)
swarm 集群由管理节点(manager)和工作节点(work node)构成。
swarm mananger:负责整个集群的管理工作包括集群配置、服务管理等所有跟集群有关的工作。一个 Swarm 集群可以有多个管理节点,但只有一个管理节点可以成为 leader,leader 通过 raft 协议实现。
为了利用swarm模式的容错功能,Docker建议根据组织的高可用性要求实现奇数个节点。当您拥有多个管理器时,您可以从管理器节点的故障中恢复而无需停机。
N个管理节点的集群容忍最多损失 (N-1)/2 个管理节点。 Docker建议一个集群最多7个管理器节点。
work node:即图中的 available node,主要负责运行相应的服务来执行任务(task)。工作节点是任务执行节点,管理节点将服务 (service) 下发至工作节点执行。管理节点默认也作为工作节点。也可以通过配置让服务只运行在管理节点。
任务 (Task)是 Swarm 中的最小的调度单位,目前来说就是一个单一的容器。
服务 (Services) 是指一组任务的集合,服务定义了任务的属性。服务有两种模式:
replicated services (复制服务)按照一定规则在各个工作节点上运行指定个数的任务。
global services (全局服务)每个工作节点上运行一个此任务。
两种模式通过 docker service create 的 --mode 参数指定。下图展示了容器、任务、服务的关系。
service 通过 ingress load balancing 来发布服务,且 swarm 集群中所有 node 都参与到 ingress 路由网格(ingress routing mesh) 中,访问任意一个 node+PublishedPort 即可访问到服务。
当访问任何节点上的端口8080时,Docker将请求路由到活动容器。在群节点本身,端口8080可能并不实际绑定,但路由网格知道如何路由流量,并防止任何端口冲突的发生。
路由网格在发布的端口上监听分配给节点的任何IP地址。对于外部可路由的IP地址,该端口可从主机外部获得。对于所有其他IP地址,只能从主机内部访问。
创建三个节点的swarm集群
角色 | IP |
---|---|
swarm-manager | 192.168.2.5 |
swarm-worker1 | 192.168.2.6 |
swarm-worker2 | 192.168.2.7 |
修改主机名
[root@localhost ~]# hostnamectl set-hostname swarm-manager
添加主机名解析
- [root@localhost ~]# cat /etc/hosts
- 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 192.168.2.5 swarm-manager
- 192.168.2.6 swarm-worker1
- 192.168.2.7 swarm-worker2
关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
关闭防火墙或开放端口
- # 查看firewalld防火墙状态
- systemctl status firewalld
-
- # 查看所有打开的端口
- firewall-cmd --zone=public --list-ports
-
- # 防火墙开放端口(更新firewalld防火墙规则后生效)
- firewall-cmd --zone=public --add-port=要开放的端口/tcp --permanent
- # 选项:
- –zone # 作用域
- –add-port=80/tcp # 添加端口,格式为:端口/通讯协议
- –permanent #永久生效,没有此参数重启后失效
- # 示例:
- firewall-cmd --zone=public --add-port=3306/tcp --permanent
-
- # firewalld防火墙关闭接口(更新firewalld防火墙规则后生效)
- firewall-cmd --zone=public --remove-port=要关闭的端口/tcp --permanent
-
- # 更新firewalld防火墙规则(并不中断用户连接,即不丢失状态信息)
- firewall-cmd --reload
-
- # 启动firewalld防火墙
- systemctl start firewalld
- # 关闭firewalld防火墙:
- systemctl stop firewalld
- # 开机禁用firewalld防火墙
- systemctl disable firewalld
- # 开机启用firewalld防火墙
- systemctl enable firewalld
1.查看当前任意一台主机的swarm状态
- [root@swarm-manager ~]# docker info -f '{{.Swarm}}'
- { inactive false [] 0 0 <nil> []}
当前状态为暂停
2.将swarm开启
- [root@swarm-manager ~]# docker swarm init
- Swarm initialized: current node (lq6vktglarbu60urm25tqn1ub) is now a manager.
-
- To add a worker to this swarm, run the following command:
-
- docker swarm join --token SWMTKN-1-5cs1bpgjxzm1v5xli77spz0ghqwne7shnz87pixwesplau9vsb-4pt0w6tmvz5vl1naqx9duc7yx 192.168.2.5:2377
-
- To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
翻译: 群初始化:当前节点(lq6vktglarbu60urm25tqn1ub)现在是一个管理器。 要向集群中添加一个工作节点,运行以下命令: docker swarm join——token swmtkn -1- 5cs1bpgjxzm1v5xli77spz0ghqwne7shnz87pixwesplau9vb -4pt0w6tmvz5vl1naqx9duc7yx 192.168.2.5:2377 要向集群中添加管理器,请运行` docker swarm join-token manager `并按照说明操作。
查看状态
- [root@swarm-manager ~]# docker info -f '{{.Swarm}}'
- {lq6vktglarbu60urm25tqn1ub 192.168.2.5 active true [{lq6vktglarbu60urm25tqn1ub 192.168.2.5:2377}] 1 1 0xc0005146e0 []}
3.将其他两台worker添加为工作节点
- [root@swarm-worker1 ~]# docker swarm join --token SWMTKN-1-5cs1bpgjxzm1v5xli77spz0ghqwne7shnz87pixwesplau9vsb-4pt0w6tmvz5vl1naqx9duc7yx 192.168.2.5:2377
- This node joined a swarm as a worker.
4.从控制节点查看
- [root@swarm-manager ~]# docker info
- Swarm: active #当前状态活跃
- NodeID: lq6vktglarbu60urm25tqn1ub
- Is Manager: true
- ClusterID: pmekmmvdxq2k7sdq4rxr9s5dn
- Managers: 1 #计算节点
- Nodes: 3 #工作节点
- Default Address Pool: 10.0.0.0/8 #默认地址池
- SubnetSize: 24
- Data Path Port: 4789 #数据通路端口
- Orchestration:
- Task History Retention Limit: 5 #任务历史记录保留限制
- Raft:
- Snapshot Interval: 10000
- Number of Old Snapshots to Retain: 0
- Heartbeat Tick: 1
- Election Tick: 10
- Dispatcher:
- Heartbeat Period: 5 seconds #心跳周期
- CA Configuration:
- Expiry Duration: 3 months
- Force Rotate: 0
- Autolock Managers: false
- Root Rotation In Progress: false
- Node Address: 192.168.2.5 #节点地址
- Manager Addresses:
- 192.168.2.5:2377 #控制节点地址
查看节点
- [root@swarm-manager ~]# docker node ls
- ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
- lq6vktglarbu60urm25tqn1ub * swarm-manager Ready Active Leader 24.0.2
- wxvvriqekwwfd46476752a818 swarm-worker1 Ready Active 20.10.24
- 0c49ooh7er8zjthhdpvw6qx8r swarm-worker2 Ready Active 20.10.24
ID:节点ID hostname:主机名 status:状态 availability:可用性 manager status:控制节点状态(leader首领,Reachable达状态) engine version:docker 版本
部署可视化docker swarm平台
docker run -d --name myui -e HOST=192.168.3.10 -e PORT=8080 -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock dockersamples/visualizer
1.将worker提升为manager
- [root@swarm-manager ~]# docker node promote wxvvriqekwwfd46476752a818
- Node wxvvriqekwwfd46476752a818 promoted to a manager in the swarm.
- [root@swarm-manager ~]# docker node ls
- ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
- lq6vktglarbu60urm25tqn1ub * swarm-manager Ready Active Leader 24.0.2
- wxvvriqekwwfd46476752a818 swarm-worker1 Ready Active Reachable 20.10.24
- 0c49ooh7er8zjthhdpvw6qx8r swarm-worker2 Ready Active 20.10.24
2.将manager降级为worker
- [root@swarm-manager ~]# docker node demote wxvvriqekwwfd46476752a818
- Manager wxvvriqekwwfd46476752a818 demoted in the swarm.
- [root@swarm-manager ~]# docker node ls
- ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
- lq6vktglarbu60urm25tqn1ub * swarm-manager Ready Active Leader 24.0.2
- wxvvriqekwwfd46476752a818 swarm-worker1 Ready Active 20.10.24
- 0c49ooh7er8zjthhdpvw6qx8r swarm-worker2 Ready Active 20.10.24
1.启动busybox
- [root@swarm-manager ~]# docker service create --name server 192.168.2.7:5000/busybox sleep 99999999
- ou5b2c1y0x0cpfq1fhjyyylfw
- overall progress: 1 out of 1 tasks
- 1/1: running
- verify: Service converged
2.查看当前swarm中的service
- [root@swarm-manager ~]# docker service ls
- ID NAME MODE REPLICAS IMAGE PORTS
- ou5b2c1y0x0c server replicated 1/1 192.168.2.7:5000/busybox:latest
3.查看当前service中的任务
- [root@swarm-manager ~]# docker service ps server
- ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
- qdsui6stwa30 server.1 192.168.2.7:5000/busybox:latest swarm-worker2 Running Running about a minute ago
上⼀节部署了只有⼀个副本的 Service,不过对于 web 服务,我们通常会运⾏多个实例。这样可以负载 均衡,同时也能提供⾼可⽤。
- [root@swarm-manager ~]# docker service scale server=5
- server scaled to 5
- overall progress: 5 out of 5 tasks
- 1/5: running
- 2/5: running
- 3/5: running
- 4/5: running
- 5/5: running
- verify: Service converged
- [root@swarm-manager ~]# docker service ls
- ID NAME MODE REPLICAS IMAGE PORTS
- ou5b2c1y0x0c server replicated 5/5 192.168.2.7:5000/busybox:latest
- [root@swarm-manager ~]# docker service ps server
- ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
- qdsui6stwa30 server.1 192.168.2.7:5000/busybox:latest swarm-worker2 Running Running 3 hours ago
- hjh9lt9pb7lo server.2 192.168.2.7:5000/busybox:latest swarm-manager Running Running 24 seconds ago
- p8drzio7um64 server.3 192.168.2.7:5000/busybox:latest swarm-worker1 Running Running 24 seconds ago
- kj5oiavoj6eq server.4 192.168.2.7:5000/busybox:latest swarm-worker1 Running Running 24 seconds ago
- xndqh90i3q8z server.5 192.168.2.7:5000/busybox:latest swarm-worker2 Running Running 24 seconds ago
swarm-manager 上的副本 web_server.2 已经被 Shutdown 了,为了达到 5 个副本数的⽬标.
- [root@swarm-manager ~]# docker service ps server
- ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
- qdsui6stwa30 server.1 192.168.2.7:5000/busybox:latest swarm-worker2 Running Running 3 hours ago
- 2x0v0jp196n7 server.2 192.168.2.7:5000/busybox:latest swarm-manager Running Running 36 seconds ago
- hjh9lt9pb7lo \_ server.2 192.168.2.7:5000/busybox:latest swarm-manager Shutdown Failed 41 seconds ago "task: non-zero exit (137)"
- p8drzio7um64 server.3 192.168.2.7:5000/busybox:latest swarm-worker1 Running Running 10 minutes ago
- 0e5acarc93nw server.4 192.168.2.7:5000/busybox:latest swarm-manager Running Running 17 seconds ago
- itoqthypjbn5 \_ server.4 192.168.2.7:5000/busybox:latest swarm-manager Shutdown Failed 22 seconds ago "task: non-zero exit (137)"
- vitawq6ny2dq \_ server.4 192.168.2.7:5000/busybox:latest swarm-manager Shutdown Failed 57 seconds ago "task: non-zero exit (137)"
- nwc6b2tmz8xq server.5 192.168.2.7:5000/busybox:latest swarm-worker2 Running Running about a minute ago
我们还可以减少副本(docker service scale server=3)
故障是在所难免的,容器可能崩溃,Docker Host 可能宕机,不过幸运的是,Swarm 已经内置了 failover 策略。 创建 service 的时候,我们没有告诉 swarm 发⽣故障时该如何处理,只是说明了我们期望的状态(⽐如 运⾏3个副本),swarm 会尽最⼤的努⼒达成这个期望状态,⽆论发⽣什么状况。 以上⼀节我们部署的 Service 为例,当前 3 个副本分布在 swarm-worker1 和 swarm-worker2 上。 现在我们测试 swarm 的 failover 特性,关闭 swarm-worker1。
Swarm 会检测到 swarm-worker1 的故障,并标记为 Down
Swarm 会将 swarm-worker1 上的副本调度到其他可⽤节点。我们可以通过 docker service ps 观察这 个 failover 过程
可以看到,web_server.1 和 web_server.2 已经从 swarm-worker1 迁移到了 swarm-worker2,之前运 ⾏在故障节点 swarm-worker1 上的副本状态被标记为 Shutdown
- [root@swarm-manager ~]# docker service ps server
- ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
- lx5x38ggwg2q server.1 192.168.2.7:5000/busybox:latest swarm-worker1 Running Running 24 seconds ago
- qdsui6stwa30 \_ server.1 192.168.2.7:5000/busybox:latest swarm-worker2 Shutdown Running 3 hours ago
- 2x0v0jp196n7 server.2 192.168.2.7:5000/busybox:latest swarm-manager Running Running 5 minutes ago
- hjh9lt9pb7lo \_ server.2 192.168.2.7:5000/busybox:latest swarm-manager Shutdown Failed 5 minutes ago "task: non-zero exit (137)"
- p8drzio7um64 server.3 192.168.2.7:5000/busybox:latest swarm-worker1 Running Running 15 minutes ago
- 0e5acarc93nw server.4 192.168.2.7:5000/busybox:latest swarm-manager Running Running 4 minutes ago
- itoqthypjbn5 \_ server.4 192.168.2.7:5000/busybox:latest swarm-manager Shutdown Failed 5 minutes ago "task: non-zero exit (137)"
- vitawq6ny2dq \_ server.4 192.168.2.7:5000/busybox:latest swarm-manager Shutdown Failed 5 minutes ago "task: non-zero exit (137)"
- aji7iovuwcms server.5 192.168.2.7:5000/busybox:latest swarm-worker1 Running Running 23 seconds ago
- nwc6b2tmz8xq \_ server.5 192.168.2.7:5000/busybox:latest swarm-worker2 Shutdown Running 6 minutes ago
- [root@swarm-manager ~]# docker service ls
- ID NAME MODE REPLICAS IMAGE PORTS
- ou5b2c1y0x0c server replicated 7/5 192.168.2.7:5000/busybox:latest
创建三台web服务器,然后更新开放端口
- [root@swarm-manager ~]# docker service create --name web-cluster --replicas=3 192.168.2.7:5000/nginx
- mhh01eix50toq0siun8lovx3u
- overall progress: 3 out of 3 tasks
- 1/3: running
- 2/3: running
- 3/3: running
- verify: Service converged
- [root@swarm-manager ~]# docker service ls
- ID NAME MODE REPLICAS IMAGE PORTS
- mhh01eix50to web-cluster replicated 3/3 192.168.2.7:5000/nginx:latest
- [root@swarm-manager ~]# docker service ps web-cluster
- ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
- jvqpztz5h3h2 web-cluster.1 192.168.2.7:5000/nginx:latest swarm-manager Running Running about a minute ago
- qoto1v5ygnq8 web-cluster.2 192.168.2.7:5000/nginx:latest swarm-worker1 Running Running about a minute ago
- no0edfd5dlag web-cluster.3 192.168.2.7:5000/nginx:latest swarm-worker2 Running Running 59 seconds ago
更新开放端口
- [root@swarm-manager ~]# docker service update --publish-add 81:80 web-cluster
- web-cluster
- overall progress: 3 out of 3 tasks
- 1/3: running
- 2/3: running
- 3/3: running
- verify: Service converged
测试
- [root@swarm-manager ~]# curl 192.168.2.5:81
- <!DOCTYPE html>
- <html>
- <head>
- <title>Welcome to nginx!</title>
- <style>
- html { color-scheme: light dark; }
- body { width: 35em; margin: 0 auto;
- font-family: Tahoma, Verdana, Arial, sans-serif; }
- </style>
- </head>
- <body>
- <h1>Welcome to nginx!</h1>
- <p>If you see this page, the nginx web server is successfully installed and
- working. Further configuration is required.</p>
-
- <p>For online documentation and support please refer to
- <a href="http://nginx.org/">nginx.org</a>.<br/>
- Commercial support is available at
- <a href="http://nginx.com/">nginx.com</a>.</p>
-
- <p><em>Thank you for using nginx.</em></p>
- </body>
- </html>
服务发现
一种实现方式是将所有service都pushlish出去,然后通过routing mesh访问。但明显的缺点是把memcached和MySQL也暴露到外网。增加了安全隐患。
如果不publish,那么swarm就要提供一种机制,能够:
让service通过简单的方法访问到其他service
当service副本的IP发生变化时,不会影响访问当service的其他的service
当service的副本数发生变化时,不会影响访问service的其他service
创建overlay网络
默认swarm自带了一种swarm网络,但是不能直接使用,因为目前ingress没有提供服务发现,必须创建自己的overlay网络
- [root@swarm-manager ~]# docker network create -d overlay my_net
- sxtupj84xfw5nmfgy3gtvdstn
- [root@swarm-manager ~]# docker network ls
- NETWORK ID NAME DRIVER SCOPE
- 43a8a43b0cb2 bridge bridge local
- 5ca5d03db71f docker_gwbridge bridge local
- c598e7da9321 host host local
- iplndsmyf02j ingress overlay swarm
- sxtupj84xfw5 my_net overlay swarm
- 7dbddfe02b0b nginxcompose_default bridge local
- 36391f761fe6 none null local
下面我们将部署三副本的服务,镜像使用nginx1.21,然后镜像更新到nginx1.24
- [root@swarm-manager ~]# docker service create --name my_web --replicas=3 192.168.2.7:5000/nginx
- iwh72vw062be9q0wn59dtwb6u
- overall progress: 3 out of 3 tasks
- 1/3: running
- 2/3: running
- 3/3: running
- verify: Service converged
- 进行滚动更新
- [root@swarm-manager ~]# docker service update --image 192.168.2.7:5000/nginx:1.24 my_web
- my_web
- overall progress: 3 out of 3 tasks
- 1/3: running
- 2/3: running
- 3/3: running
- verify: Service converged
swarm将按照如下步骤执行滚动更新
停止第一个副本
调度任务,选择worker node
在work上用新的镜像启动副本
如果副本运行成功,继续更新下一个副本,如果失败,暂停整个更新过程
将容器版本进行回滚
- [root@swarm-manager ~]# docker service update --rollback my_web
- my_web
- rollback: manually requested rollback
- overall progress: rolling back update: 3 out of 3 tasks
- 1/3: running
- 2/3: running
- 3/3: running
- verify: Service converged
replicated mode是默认容器副本调度器
此模式特别适合需要运行daemon的集群环境中,比如ELK中的logstash应用,需要每一台的节点中安装。
- [root@swarm-manager ~]# docker service create --name logstash --mode global 192.168.2.7:5000/logstash
- u917nkoedy5g1werfpfjyn7ur
- overall progress: 3 out of 3 tasks
- ovq797qe93og: running
- dq5uvz4d6l26: running
- u5dkxblsfm20: running
- verify: Service converged
- [root@swarm-manager ~]# docker service ps logstash
- ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
- p2jv6hka6ryf logstash.dq5uvz4d6l26ljgku8ierpclr 192.168.2.7:5000/logstash:latest swarm-worker1 Running Running 10 seconds ago
- 3cjbksmengrz \_ logstash.dq5uvz4d6l26ljgku8ierpclr 192.168.2.7:5000/logstash:latest swarm-worker1 Shutdown Complete 16 seconds ago
- 2jgciu480j8u logstash.ovq797qe93ogm8jtnzmbd3iyn 192.168.2.7:5000/logstash:latest swarm-worker2 Running Running 5 seconds ago
- 8rnmy2r8bjem \_ logstash.ovq797qe93ogm8jtnzmbd3iyn 192.168.2.7:5000/logstash:latest swarm-worker2 Shutdown Complete 10 seconds ago
- vx8fg29wgyar logstash.u5dkxblsfm203ra01pw64ijkf 192.168.2.7:5000/logstash:latest swarm-manager Running Running 5 seconds ago
- jqbx2qarzdsn \_ logstash.u5dkxblsfm203ra01pw64ijkf 192.168.2.7:5000/logstash:latest swarm-manager Shutdown Complete 11 seconds ago
- wqskfy4eqfz0 \_ logstash.u5dkxblsfm203ra01pw64ijkf 192.168.2.7:5000/logstash:latest swarm-manager Shutdown Complete 24 seconds ago
- 40t8ln0v7if5 \_ logstash.u5dkxblsfm203ra01pw64ijkf 192.168.2.7:5000/logstash:latest swarm-manager Shutdown Complete 39 seconds ago
副本运行在那些节点都是由swarm决定的,作为用户我们使用label精细控制service的运行位置
逻辑分两步:
为每个node定义label
设置service运行在指定label的node上。
- [root@swarm-manager ~]# docker node ls
- ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
- u5dkxblsfm203ra01pw64ijkf * swarm-manager Ready Active Leader 24.0.2
- dq5uvz4d6l26ljgku8ierpclr swarm-worker1 Ready Active 20.10.24
- ovq797qe93ogm8jtnzmbd3iyn swarm-worker2 Ready Active 20.10.24
- [root@swarm-manager ~]# docker node update --label-add env=test swarm-worker1
- swarm-worker1
- [root@swarm-manager ~]#
- [root@swarm-manager ~]# docker service create --constraint node.labels.env==test --replicas=3 --name my_web1 192.168.2.7:5000/nginx
- fys9voiig2i2wfuszeuudnb1f
- overall progress: 3 out of 3 tasks
- 1/3: running
- 2/3: running
- 3/3: running
- verify: Service converged
- [root@swarm-manager ~]# docker service ps my_web1
- ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
- xdumy7nzezi2 my_web1.1 192.168.2.7:5000/nginx:latest swarm-worker1 Running Running 19 seconds ago
- iq1p9ra0vxto my_web1.2 192.168.2.7:5000/nginx:latest swarm-worker1 Running Running 20 seconds ago
- zdckyjvqj2nb my_web1.3 192.168.2.7:5000/nginx:latest swarm-worker1 Running Running 19 seconds ago
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。