Deployment 为 Pod 和Replica Set(升级版的 Replication Controller)提供声明式更新。 Deployment 主要职责是为了保证 pod 的数量和健康,可以看做新一代的Replication Controller。

Deployment Update

例:让 nextcloud pod 使用nextcloud:13.0.6-apache的镜像来代替原来的nextcloud:13.0.5-apache的镜像。

## 
[root@ec-k8s-m1 ~]# kubectl get deployments
NAME                     DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nextcloud                1         1         1            1           6d
nextcloud-mysql          1         1         1            1           7d
nfs-client-provisioner   1         1         1            1           8d
方法一: kubectl edit
## 使用默认编辑器,编辑服务器上定义的资源。
## 修改“image: nextcloud:13.0.5-apache”为“image: nextcloud:13.0.6-apache”
[root@ec-k8s-m1 ~]# kubectl edit deployment/nextcloud
deployment.extensions/nextcloud edited
## 使用指定的编辑器 
[root@ec-k8s-m1 ~]# KUBE_EDITOR="vim" kubectl edit deployment/nextcloud
方法二:kubectl set image
##  
[root@ec-k8s-m1 ~]# kubectl set image deployment/nextcloud nextcloud=nextcloud:13.0.6-apache
deployment "nextcloud" image updated

Check Status

##  
[root@ec-k8s-m1 ~]# kubectl rollout status deployment/nextcloud
deployment "nextcloud" successfully rolled out
##  Get ReplicaSet 
[root@ec-k8s-m1 ~]# kubectl get rs
NAME                                DESIRED   CURRENT   READY     AGE
nextcloud-7f5744bf7b                0         0         0         7d
nextcloud-8699599cc7                1         1         1         10m
nextcloud-mysql-85b55566b8          1         1         1         7d
nfs-client-provisioner-7fd8b59497   1         1         1         9d

##  
[root@ec-k8s-m1 ~]# kubectl get pods
NAME                                      READY     STATUS    RESTARTS   AGE
nextcloud-8699599cc7-cr58v                1/1       Running   0          11m
nextcloud-mysql-85b55566b8-kwcwn          1/1       Running   0          7d
nfs-client-provisioner-7fd8b59497-9d6gx   1/1       Running   4          9d
##
[root@ec-k8s-m1 ~]# kubectl rollout history deployment/nextcloud
deployments "nextcloud"
REVISION  CHANGE-CAUSE
1         <none>
2         <none>
nextcloud:13.0.6-apache

Roll Back

## 回退当前的 rollout 到之前的版本
[root@ec-k8s-m1 ~]# kubectl rollout undo deployment/nextcloud
## 使用 --revision参数指定某个历史版本
[root@ec-k8s-m1 ~]# kubectl rollout undo deployment/nextcloud --to-revision=1

参考资料:
http://docs.kubernetes.org.cn/