linuxea:Docker swarm集群节点服务更新(2)


我们用redis做为基础进行,进行部署,使用dockerhub的image,和(1)结构一样

I. 更新

创建一个服务

[root@DS-VM-Node117-117-linuxea ~]# docker service create \
> --replicas 3 \
> --name redis \
> --update-delay 10s \
> marksugar/redis:1
4bv0yd0rylekh6i7t3efswy8t
[root@DS-VM-Node117-117-linuxea ~]# 

--update-delay标志配置服务任务或任务集之间的更新之间的时间延迟。您可以将时间描述T为秒Ts,分钟Tm或小时数的组合Th。0m30s表示10分30秒的延迟

查看节点信息

[root@DS-VM-Node117-117-linuxea ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND       CREATED         STATUS        PORTS                 NAMES
dda61442874f        marksugar/redis:1   "/start.sh"   4 minutes ago   Up 4 minutes  6379/tcp, 26379/tcp   redis.2.0oq4tgo5016im6pyy8eigyed0
[root@DS-VM-Node98-linuxea /data/rds]# docker ps -a                           
CONTAINER ID        IMAGE               COMMAND       CREATED         STATUS         PORTS                 NAMES
8368afff7aae        marksugar/redis:1   "/start.sh"   4 minutes ago   Up 4 minutes   6379/tcp, 26379/tcp   redis.1.bmyko14s690hogqrlff8db130
[root@DS-VM-Node98 /data/rds]#                                                                                             
[root@DS-VM-Node114-linuxea ~]# docker ps -a                                  
CONTAINER ID        IMAGE               COMMAND       CREATED         STATUS        PORTS                 NAMES
a835f7ec1c78        marksugar/redis:1   "/start.sh"   5 minutes ago   Up 4 minutes  6379/tcp, 26379/tcp   redis.3.cpo3lss13l9vt7s9rqxi5pszb

检查redis服务

[root@DS-VM-Node117-117-linuxea ~]# docker service inspect --pretty redis
ID:     4bv0yd0rylekh6i7t3efswy8t
Name:       redis
Mode:       Replicated
 Replicas:  3
Placement:
UpdateConfig:
 Parallelism:   1
 Delay:     10s
 On failure:    pause
ContainerSpec:
 Image:     marksugar/redis:1
Resources:

更新

迭代到redis:2

[root@DS-VM-Node117-117-linuxea ~]# docker service update --image marksugar/redis:2 redis
redis
  • 默认情况下,调度程序应用滚动更新如下:

  •   停止第一个任务
    
  •   计划已停止任务的更新。
    
  •   启动更新任务的容器。
    
  •   如果任务的更新返回RUNNING,等待指定的延迟时间,然后启动下一个任务。
    
  •   如果在更新期间的任何时间任务返回FAILED,则暂停更新。
    

查看滚动更新信息

[root@DS-VM-Node117-117-linuxea ~]# docker service inspect --pretty redis
ID:     4bv0yd0rylekh6i7t3efswy8t
Name:       redis
Mode:       Replicated
 Replicas:  3
Update status:
 State:     completed
 Started:   4 minutes ago
 Completed: 2 minutes ago
 Message:   update completed
Placement:
UpdateConfig:
 Parallelism:   1
 Delay:     10s
 On failure:    pause
ContainerSpec:
 Image:     marksugar/redis:2
Resources:

观察动作完成度

[root@DS-VM-Node117-117-linuxea ~]# docker service ps redis 
ID                         NAME         IMAGE              NODE                       DESIRED STATE  CURRENT STATE                    ERROR
9nv4wbflniq85iowfhpuqeow6  redis.1      marksugar/redis:2  DS-VM-Node117-117-linuxea.cluster.com  Running        Running 22 seconds ago           
bmyko14s690hogqrlff8db130   \_ redis.1  marksugar/redis:1  DS-VM-Node98.cluster.com   Shutdown       Shutdown less than a second ago  
1rrmo8ekz7soaytpwx7hbd1kp  redis.2      marksugar/redis:2  DS-VM-Node98.cluster.com   Running        Running less than a second ago   
0oq4tgo5016im6pyy8eigyed0   \_ redis.2  marksugar/redis:1  DS-VM-Node117-117-linuxea.cluster.com  Shutdown       Shutdown 44 seconds ago          
28ox09frhbyjvfotual17p03j  redis.3      marksugar/redis:2  DS-VM-Node117-117-linuxea.cluster.com  Ready          Ready 9 seconds ago              
cpo3lss13l9vt7s9rqxi5pszb   \_ redis.3  marksugar/redis:1  DS-VM-Node114.cluster.com  Shutdown       Running 21 minutes ago           
[root@DS-VM-Node117-117-linuxea ~]# 

如果失败而暂停这需要重新启动暂停的更新服务 docker service update redis

更新完成

等待几分钟后滚动更新完成:

[root@DS-VM-Node117-117-linuxea ~]# docker service ps redis 
ID                         NAME         IMAGE              NODE                       DESIRED STATE  CURRENT STATE                    ERROR
9nv4wbflniq85iowfhpuqeow6  redis.1      marksugar/redis:2  DS-VM-Node117-117-linuxea.cluster.com  Running        Running about a minute ago       
bmyko14s690hogqrlff8db130   \_ redis.1  marksugar/redis:1  DS-VM-Node98.cluster.com   Shutdown       Shutdown less than a second ago  
1rrmo8ekz7soaytpwx7hbd1kp  redis.2      marksugar/redis:2  DS-VM-Node98.cluster.com   Running        Running less than a second ago   
0oq4tgo5016im6pyy8eigyed0   \_ redis.2  marksugar/redis:1  DS-VM-Node117-117-linuxea.cluster.com  Shutdown       Shutdown 2 minutes ago           
28ox09frhbyjvfotual17p03j  redis.3      marksugar/redis:2  DS-VM-Node117-117-linuxea.cluster.com  Running        Running about a minute ago       
cpo3lss13l9vt7s9rqxi5pszb   \_ redis.3  marksugar/redis:1  DS-VM-Node114.cluster.com  Shutdown       Shutdown less than a second ago  
[root@DS-VM-Node117-117-linuxea ~]# 

II. 排除

如果此时我需要保留一个节点不被更新,这可以排除

drain

[root@DS-VM-Node117-linuxea ~]# docker node update --availability drain DS-VM-Node117.cluster.com 
DS-VM-Node117.cluster.com

在查看已经被排除,不会被更新

[root@DS-VM-Node117-linuxea ~]# docker node inspect --pretty DS-VM-Node117.cluster.com 
ID:         as4u4yh1h5h84y06h2etad4yb
Hostname:       DS-VM-Node117.cluster.com
Joined at:      2017-07-28 05:16:16.888583447 +0000 utc
Status:
 State:         Ready
 Availability:      Drain
Manager Status:
 Address:       10.10.240.117:2377
 Raft Status:       Reachable
 Leader:        Yes
Platform:
 Operating System:  linux
 Architecture:      x86_64
Resources:
 CPUs:          1
 Memory:        3.858 GiB
Plugins:
  Network:      bridge, host, null, overlay
  Volume:       local
Engine Version:     1.12.3
[root@DS-VM-Node117-linuxea ~]# 

可以看出117被分离,并没有更新到117机器上

[root@DS-VM-Node117-linuxea ~]# docker service ps redis 
ID                         NAME         IMAGE              NODE                       DESIRED STATE  CURRENT STATE                    ERROR
361rt5z5scr3i4ezx3c5fmkmg  redis.1      marksugar/redis:1  DS-VM-Node98.cluster.com   Running        Running less than a second ago               
2gxzej0b0zjnlz9qcqs2f02ym  redis.2      marksugar/redis:1  DS-VM-Node98.cluster.com   Running        Running less than a second ago             
36kam6gq0x72s6443v8o3awub  redis.3      marksugar/redis:1  DS-VM-Node114.cluster.com  Running        Starting less than a second ago 

active

[root@DS-VM-Node117-linuxea ~]# docker node update --availability active DS-VM-Node117.cluster.com 
DS-VM-Node117.cluster.com
[root@DS-VM-Node117 ~]# docker node inspect --pretty DS-VM-Node117.cluster.com 
ID:         as4u4yh1h5h84y06h2etad4yb
Hostname:       DS-VM-Node117.cluster.com
Joined at:      2017-07-28 05:16:16.888583447 +0000 utc
Status:
 State:         Ready
 Availability:      Active
Manager Status:
 Address:       10.10.240.117:2377
 Raft Status:       Reachable
 Leader:        Yes
Platform:
 Operating System:  linux
 Architecture:      x86_64
Resources:
 CPUs:          1
 Memory:        3.858 GiB
Plugins:
  Network:      bridge, host, null, overlay
  Volume:       local
Engine Version:     1.12.3
0 分享

您可以选择一种方式赞助本站

支付宝扫码赞助

支付宝扫码赞助

日期: 2017-07-29分类: Docker

标签: docker, swarm

发表评论