测试开发技术网站
博客
设计
设计
开发
Python
测试
unittest
运维
Linux基础应用
CI/CD
CI/CD
数据库
数据库
云计算
云计算
云原生
云原生
爬虫
爬虫
数据分析
数据分析
人工智能
人工智能
登录
注册
Docker----DockerSwarm集群环境弹性服务动态扩缩容
收藏本文
作者:redrose2100 类别: 日期:2022-05-03 14:32:58 阅读:863 次 消耗积分:0 分
![](https://redrose2100.oss-cn-hangzhou.aliyuncs.com/img/06c9f19c-9517-11ee-b9ec-0242ac110004.png) [TOC] ### (1)本文在[Docker----DockerSwarm集群环境搭建](http://blog.redrose2100.com/article/71) 的环境基础上 如下,有三个manager节点(192.168.145.128,192.168.145.129,192.168.145.130)和一个worker节点(192.168.145.131) ```bash [root@localhost ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION fhpe4p0m4gb47pxh48kf9psp8 localhost.localdomain Ready Active Reachable 20.10.10 p1cfiyfyxgkhupjj03tvq40ph localhost.localdomain Ready Active Reachable 20.10.10 wsqaq4isrzhlgphnnaqxucy6r * localhost.localdomain Ready Active Leader 20.10.10 xlgi99te9cchyz9n3ydkycf6k localhost.localdomain Ready Active 20.10.10 [root@localhost ~]# ``` ### (2)查看docker service 帮助文档 ```bash [root@localhost ~]# docker service --help Usage: docker service COMMAND Manage services Commands: create Create a new service inspect Display detailed information on one or more services logs Fetch the logs of a service or task ls List services ps List the tasks of one or more services rm Remove one or more services rollback Revert changes to a service's configuration scale Scale one or multiple replicated services update Update a service Run 'docker service COMMAND --help' for more information on a command. [root@localhost ~]# ``` ### (3)创建集群服务 如下,在一个manager集群节点上(192.168.145.128)创建一个Nginx集群服务,对外暴露端口8080,映射到内部80端口,设置副本数为2 ```bash [root@localhost ~]# docker service create --name nginx_service -p 8080:80 --replicas 2 nginx j2jgvfdfyqgcsf1zcii23djul overall progress: 2 out of 2 tasks 1/2: running [==================================================>] 2/2: running [==================================================>] verify: Service converged [root@localhost ~]# ``` ### (4)查看已创建的集群服务 ```bash [root@localhost ~]# docker service ls ID NAME MODE REPLICAS IMAGE PORTS j2jgvfdfyqgc nginx_service replicated 2/2 nginx:latest *:8080->80/tcp [root@localhost ~]# ``` ### (5)查看已经创建的容器 如下,发现在192.168.145.128和192.168.145.129上分别启动了一个docker,这是因为设置了副本数为2 ```bash [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c01d7f019abd nginx:latest "/docker-entrypoint.…" 4 minutes ago Up 4 minutes 80/tcp nginx_service.2.k3zo9jubllvv95muy3l4gydf3 [root@localhost ~]# ``` ### (6)在浏览器访问,正常 ![](/static/upload/20220503_143132.png) ### (7)动态扩容服务 在其中一个manager节点执行扩容操作,设置副本数为10 ```bash [root@localhost ~]# docker service update --replicas 10 nginx_service nginx_service overall progress: 10 out of 10 tasks 1/10: running [==================================================>] 2/10: running [==================================================>] 3/10: running [==================================================>] 4/10: running [==================================================>] 5/10: running [==================================================>] 6/10: running [==================================================>] 7/10: running [==================================================>] 8/10: running [==================================================>] 9/10: running [==================================================>] 10/10: running [==================================================>] verify: Service converged [root@localhost ~]# ``` ### (8)查看各个节点docker数量 发现在各个节点上共创建了10个正常的docker,因为设置了副本数为10 ```bash [root@localhost ~]# docker service ps nginx_service ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS u41u5xs2sx4u nginx_service.1 nginx:latest localhost.localdomain Running Running 47 seconds ago jnyxv9jftpj5 nginx_service.2 nginx:latest localhost.localdomain Running Running 3 seconds ago s823t867u872 nginx_service.3 nginx:latest localhost.localdomain Running Running 32 seconds ago dshe3f5rfkza \_ nginx_service.3 nginx:latest localhost.localdomain Shutdown Failed 3 seconds ago "error creating external conne…" 8r80ylbz4v8c \_ nginx_service.3 nginx:latest localhost.localdomain Shutdown Rejected 4 seconds ago "error creating external conne…" mwo0vxu9zd4d \_ nginx_service.3 nginx:latest localhost.localdomain Shutdown Failed 5 seconds ago "error creating external conne…" c8f19q3tge0s nginx_service.4 nginx:latest localhost.localdomain Running Running 4 seconds ago 01smx140ihm6 nginx_service.5 nginx:latest localhost.localdomain Running Running less than a second ago 9onahdwcgfdg \_ nginx_service.5 nginx:latest localhost.localdomain Shutdown Rejected less than a second ago "error creating external conne…" ulr5ntbeqltz \_ nginx_service.5 nginx:latest localhost.localdomain Shutdown Rejected 13 seconds ago "error creating external conne…" c7rbpp5hcadx \_ nginx_service.5 nginx:latest localhost.localdomain Shutdown Failed 14 seconds ago "error creating external conne…" k8u10ncvdpje nginx_service.6 nginx:latest localhost.localdomain Running Running 33 seconds ago n8rvtsglqrum \_ nginx_service.6 nginx:latest localhost.localdomain Shutdown Rejected 8 seconds ago "error creating external conne…" kfm79fl5773k \_ nginx_service.6 nginx:latest localhost.localdomain Shutdown Failed 9 seconds ago "error creating external conne…" ep3mz85cq42q \_ nginx_service.6 nginx:latest localhost.localdomain Shutdown Rejected 6 seconds ago "error creating external conne…" t53va7itdkj8 nginx_service.7 nginx:latest localhost.localdomain Running Running 3 seconds ago 0uozqvv5gx9r nginx_service.8 nginx:latest localhost.localdomain Running Running 47 seconds ago 7u58boi8oppy nginx_service.9 nginx:latest localhost.localdomain Running Running less than a second ago p1pzcqsgfaoo \_ nginx_service.9 nginx:latest localhost.localdomain Shutdown Failed less than a second ago "error creating external conne…" p34rm7b9309p \_ nginx_service.9 nginx:latest localhost.localdomain Shutdown Failed less than a second ago "error creating external conne…" 1lgbmlxpnf32 \_ nginx_service.9 nginx:latest localhost.localdomain Shutdown Rejected 14 seconds ago "error creating external conne…" yo0zcq4vej8i nginx_service.10 nginx:latest localhost.localdomain Running Running 47 seconds ago [root@localhost ~]# ``` ### (9)动态缩容 如下,设置副本数为4 ```bash [root@localhost ~]# docker service update --replicas 4 nginx_service nginx_service overall progress: 4 out of 4 tasks 1/4: running [==================================================>] 2/4: running [==================================================>] 3/4: running [==================================================>] 4/4: running [==================================================>] verify: Service converged [root@localhost ~]# ``` ### (10)查看各个节点docker数量 然后查看发现各个节点docker总数压缩为4个了 ```bash [root@localhost ~]# docker service ps nginx_service ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS zm51ipb5u3zk nginx_service.1 nginx:latest localhost.localdomain Running Running 14 minutes ago k3zo9jubllvv nginx_service.2 nginx:latest localhost.localdomain Running Running 14 minutes ago lfjg4kovkuu2 \_ nginx_service.2 nginx:latest localhost.localdomain Shutdown Rejected 14 minutes ago "error creating external conne…" ph1p09dnzzol \_ nginx_service.2 nginx:latest localhost.localdomain Shutdown Rejected 14 minutes ago "error creating external conne…" twg01hlw9lge \_ nginx_service.2 nginx:latest localhost.localdomain Shutdown Rejected 14 minutes ago "error creating external conne…" 6sccd1tvt8rq nginx_service.3 nginx:latest localhost.localdomain Running Running 4 minutes ago y3lk71ay7tqn \_ nginx_service.3 nginx:latest localhost.localdomain Shutdown Rejected 4 minutes ago "error creating external conne…" 7oqy4e593wo8 \_ nginx_service.3 nginx:latest localhost.localdomain Shutdown Failed 4 minutes ago "error creating external conne…" 97wxj8kyr4be nginx_service.6 nginx:latest localhost.localdomain Running Running 4 minutes ago 1hvkth5ioau2 \_ nginx_service.6 nginx:latest localhost.localdomain Shutdown Rejected 4 minutes ago "error creating external conne…" svwo7uyxqomp \_ nginx_service.6 nginx:latest localhost.localdomain Shutdown Rejected 4 minutes ago "error creating external conne…" xv3ao9argjwo \_ nginx_service.6 nginx:latest localhost.localdomain Shutdown Rejected 4 minutes ago "error creating external conne…" sdsay83pvtz2 \_ nginx_service.6 nginx:latest localhost.localdomain Shutdown Rejected 4 minutes ago "error creating external conne…" [root@localhost ~]# ``` ### (11)如此便可实现集群服务的控台扩缩容了
始终坚持开源开放共享精神,同时感谢您的充电鼓励和支持!
版权所有,转载本站文章请注明出处:redrose2100, http://blog.redrose2100.com/article/72
上一篇:
Docker----DockerSwarm集群环境搭建
下一篇:
Python虚拟环境管理----pipenv 虚拟环境管理工具的使用方法
搜索
个人成就
出版书籍
《Pytest企业级应用实战》
测试开发技术全栈公众号
测试开发技术全栈公众号
DevOps技术交流微信群
加微信邀请进群
常用网站链接
开源软件洞察
云原生技术栈全景图
Python语言官方文档
Golang官方文档
Docker官方文档
Jenkins中文用户手册
Scrapy官方文档
VUE官方文档
Harbor官方文档
openQA官方文档
云原生开源社区
开源中国
Kubernetes中文文档
Markdown语法官方教程
Kubernetes中文社区
Kubersphere官方文档
BootStrap中文网站
JavaScript中文网
NumPy官方文档
Pandas官方文档
GitLink确实开源网站
数据库排名网站
编程语言排名网站
SEO综合查询网站
数学加减法练习自动生成网站
Kickstart Generator
文章分类
最新文章
最多阅读
特别推荐
×
Close
登录
注册
找回密码
登录邮箱:
登录密码:
图片验证码:
注册邮箱:
注册密码:
邮箱验证码:
发送邮件
注册邮箱:
新的密码:
邮箱验证码:
发送邮件