更新某个服务时,如果该服务包括超过一个以上容器(使用 scale 标签定义),在第 n 个容器更新成功后,再去做第 n+1 个容器的更新,以此来最小化停止服务时间。
[backcolor=transparent]示例:
部署 WordPress 服务,通过scale标签指定部署 2 个容器,使用rolling_updates标签可以使 WordPress 对外停止服务的时间最小化。
- [backcolor=transparent]web[backcolor=transparent]:
- [backcolor=transparent] image[backcolor=transparent]:[backcolor=transparent] wordpress
- [backcolor=transparent] ports[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]80
- [backcolor=transparent] restart[backcolor=transparent]:[backcolor=transparent] always
- [backcolor=transparent] links[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]'db:mysql'
- [backcolor=transparent] labels[backcolor=transparent]:
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]logs[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]/var/[backcolor=transparent]log
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]routing[backcolor=transparent].[backcolor=transparent]port_80[backcolor=transparent]:[backcolor=transparent] http[backcolor=transparent]:[backcolor=transparent]//wordpress
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]rolling_updates[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]'true'
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]scale[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]'2'
- [backcolor=transparent]db[backcolor=transparent]:
- [backcolor=transparent] image[backcolor=transparent]:[backcolor=transparent] mariadb
- [backcolor=transparent] environment[backcolor=transparent]:
- [backcolor=transparent] MYSQL_ROOT_PASSWORD[backcolor=transparent]:[backcolor=transparent] example
- [backcolor=transparent] restart[backcolor=transparent]:[backcolor=transparent] always
- [backcolor=transparent] labels[backcolor=transparent]:
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]logs[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]/var/[backcolor=transparent]log[backcolor=transparent]/[backcolor=transparent]mysql
parallelism
您可以使用 parallelism 标签定义 rolling_updates 每次并行更新的容器数量。
[backcolor=transparent]注意:此标签必须和 rolling_update 配合使用,单独使用无效。
[backcolor=transparent]取值:
- 默认值为 1,即每次只更新一个容器。
- 当其值大于 1 的时候,rolling_updates 过程中,每次会以 parallelism 定义的值来并行更新相应个数的容器,实现批量更新。
- 当定义值无效时,默认为 1。[backcolor=transparent]注意:为了确保始终有容器在提供服务,建议 parallelism 定义的值小于服务包含的容器数。
[backcolor=transparent]示例:
下面的示例部署 Nginx 服务,通过 scale 标签部署 3 个容器,使用 rolling_updates 和 parallelism 标签定义每次以 2 个容器为单位来进行批量更新。
- [backcolor=transparent]web[backcolor=transparent]:
- [backcolor=transparent] image[backcolor=transparent]:[backcolor=transparent] nginx[backcolor=transparent]:[backcolor=transparent]latest
- [backcolor=transparent] restart[backcolor=transparent]:[backcolor=transparent] always
- [backcolor=transparent] environment[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]"reschedule:on-node-failure"
- [backcolor=transparent] ports[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]80
- [backcolor=transparent] labels[backcolor=transparent]:
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]scale[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"3"
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]rolling_updates[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]'true'
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]rolling_updates[backcolor=transparent].[backcolor=transparent]parallelism[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"2"