kubernetes rolling update

Rolling update

1. Create Deployment

# kubectl apply -f wether.cm.yaml
# kubectl apply -f weather-jmx.deploy.yaml --record

产生了新的rs 。

[root@k8s-master ~]# kubectl get rs -w | egrep "jmx|NAME"
NAME                    DESIRED     CURRENT     READY       AGE
weather-jmx-1809594718   3           3           3          35s

2. Update image

模拟版本升级,更换deployment 中使用的镜像。

这里以直接修改yaml文件为例:
用文本编辑器打开weather-jmx.deploy.yaml, 将镜像改为:

172.16.18.5:30088/admin/centos7.1-v1-wth:test

执行:

[root@k8s-master ~]# kubectl replace -f weather-jmx.deploy.yaml --record
deployment "weather-jmx" replaced

3. Observation

[root@k8s-master ~]# kubectl get rs -w | egrep "jmx"
weather-jmx-1809594718        3         3         3         52s
weather-jmx-790510206   1         0         0         0s
weather-jmx-1809594718   2         3         3         9m
weather-jmx-790510206   1         0         0         0s
weather-jmx-790510206   1         1         0         0s
weather-jmx-1809594718   2         3         3         9m
weather-jmx-1809594718   2         2         2         9m
weather-jmx-790510206   2         1         0         0s
weather-jmx-790510206   2         1         0         0s
weather-jmx-790510206   2         2         0         0s
weather-jmx-790510206   2         2         1         4s
weather-jmx-1809594718   1         2         2         9m
weather-jmx-1809594718   1         2         2         9m
weather-jmx-790510206   3         2         1         4s
weather-jmx-1809594718   1         1         1         9m
weather-jmx-790510206   3         2         1         4s
weather-jmx-790510206   3         3         1         4s
weather-jmx-790510206   3         3         2         6s
weather-jmx-1809594718   0         1         1         9m
weather-jmx-1809594718   0         1         1         9m
weather-jmx-1809594718   0         0         0         9m
weather-jmx-790510206   3         3         3         7s

通过 kubectl get rs -w 命令可以观察到,更新镜像后创建了一个新的rs.
从上图可以看出,新的rs 从1开始,逐渐的替换掉来原来的3个pod. 而原来的rs也由3个pod,逐渐变为0个pod. 由此完成了整个滚动升级的过程。
升级完成

可以通过 rollout history 来查看Deployment的滚动日志。

[root@k8s-master ~]# kubectl rollout history deployment/weather-jmx
deployments "weather-jmx"
REVISION    CHANGE-CAUSE
1       kubectl apply -f weather-jmx.deploy.yaml --record
2       kubectl replace -f weather-jmx.deploy.yaml --record

4. Rollback

如果需要回退到上个版本,执行:

[root@k8s-master ~]# kubectl rollout undo deployment/weather-jmx
deployment "weather-jmx" rolled back

回退过程同滚动升级过程一致:

[root@k8s-master ~]# kubectl get rs -w | egrep "jmx"
weather-jmx-1809594718        0         0         0         13m
weather-jmx-790510206         3         3         3         3m
weather-jmx-1809594718   0         0         0         13m
weather-jmx-1809594718   1         0         0         13m
weather-jmx-790510206   2         3         3         4m
weather-jmx-1809594718   1         0         0         13m
weather-jmx-1809594718   1         1         0         13m
weather-jmx-790510206   2         3         3         4m
weather-jmx-790510206   2         2         2         4m
weather-jmx-1809594718   2         1         0         13m
weather-jmx-1809594718   2         1         0         13m
weather-jmx-1809594718   2         2         0         13m
weather-jmx-1809594718   2         2         1         13m
weather-jmx-790510206   1         2         2         4m
weather-jmx-790510206   1         2         2         4m
weather-jmx-1809594718   3         2         1         13m
weather-jmx-790510206   1         1         1         4m
weather-jmx-1809594718   3         2         1         13m
weather-jmx-1809594718   3         3         1         13m
weather-jmx-1809594718   3         3         2         13m
weather-jmx-790510206   0         1         1         4m
weather-jmx-790510206   0         1         1         4m
weather-jmx-790510206   0         0         0         4m
weather-jmx-1809594718   3         3         3         13m
[root@k8s-master ~]# kubectl rollout history deployment/weather-jmx
deployments "weather-jmx"
REVISION    CHANGE-CAUSE
2       kubectl replace -f weather-jmx.deploy.yaml --record
3       kubectl apply -f weather-jmx.deploy.yaml --record

通过 rollout history 可以发现,当前的revision 为3。也可以通过

# kubectl rollout undo deployment/weather-jmx --revision=<REVISION>

来回退到具体某个版本

参考链接:

https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

https://tachingchen.com/tw/blog/Kubernetes-Rolling-Update-with-Deployment/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值