Rolling Update 滚动更新
跳到导航
跳到搜索
更新
** 7.1 practice evan@k8s-master:~$ kubectl get deployment httpd -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR httpd 2/3 3 2 68s httpd httpd:2.2.31 run=httpd evan@k8s-master:~$ kubectl get pod \NAME READY STATUS RESTARTS AGE httpd-5ddb558f47-2pmhw 1/1 Running 0 78s httpd-5ddb558f47-rwbhc 1/1 Running 0 78s httpd-5ddb558f47-xtfb2 0/1 ImagePullBackOff 0 78s evan@k8s-master:~$ kubectl get pod NAME READY STATUS RESTARTS AGE httpd-5ddb558f47-2pmhw 1/1 Running 0 12m httpd-5ddb558f47-rwbhc 1/1 Running 0 12m httpd-5ddb558f47-xtfb2 1/1 Running 0 12m evan@k8s-master:~$ kubectl get deployment httpd -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR httpd 3/3 3 3 12m httpd httpd:2.2.31 run=httpd evan@k8s-master:~$ kubectl get replicaset -o wide NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR httpd-5ddb558f47 3 3 3 13m httpd httpd:2.2.31 pod-template-hash=5ddb558f47,run=httpd 将配置文件中 httpd:2.2.31 替换为 httpd:2.2.32,再次执行 kubectl apply ---- ------ ---- ---- ------- Normal ScalingReplicaSet 16m deployment-controller Scaled up replica set httpd-5ddb558f47 to 3 Normal ScalingReplicaSet 99s deployment-controller Scaled up replica set httpd-8bdffc6d8 to 1 Normal ScalingReplicaSet 99s deployment-controller Scaled down replica set httpd-5ddb558f47 to 2 Normal ScalingReplicaSet 98s deployment-controller Scaled up replica set httpd-8bdffc6d8 to 2 Normal ScalingReplicaSet 6s deployment-controller Scaled down replica set httpd-5ddb558f47 to 1 Normal ScalingReplicaSet 6s deployment-controller Scaled up replica set httpd-8bdffc6d8 to 3 ---- ------ ---- ---- ------- Normal ScalingReplicaSet 16m deployment-controller Scaled up replica set httpd-5ddb558f47 to 3 Normal ScalingReplicaSet 99s deployment-controller Scaled up replica set httpd-8bdffc6d8 to 1 Normal ScalingReplicaSet 99s deployment-controller Scaled down replica set httpd-5ddb558f47 to 2 Normal ScalingReplicaSet 98s deployment-controller Scaled up replica set httpd-8bdffc6d8 to 2 Normal ScalingReplicaSet 6s deployment-controller Scaled down replica set httpd-5ddb558f47 to 1 Normal ScalingReplicaSet 6s deployment-controller Scaled up replica set httpd-8bdffc6d8 to 3
回滚
** 7.2 回滚 ubectl apply 每次更新应用时 Kubernetes 都会记录下当前的配置,保存为一个 revision(版次),这样就可以回滚到某个特定 revision。 默认配置下,Kubernetes 只会保留最近的几个 revision,可以在 Deployment 配置文件中通过 revisionHistoryLimit 属性增加 revision 数量。 下面实践回滚功能。应用有如下三个配置文件 httpd.v1.yml,httpd.v2.yml 和 httpd.v3.yml,分别对应不同的 httpd 镜像 2.4.16,2.4.17 和 2.4.18: evan@k8s-master:~$ kubectl apply -f httpd.v1.yml --record deployment.extensions/httpd created evan@k8s-master:~$ kubectl get deployment httpd -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR httpd 0/3 3 0 3s httpd httpd:2.4.16 run=httpd evan@k8s-master:~$ kubectl apply -f httpd.v2.yml --record deployment.extensions/httpd configured evan@k8s-master:~$ kubectl get deployment httpd -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR httpd 0/3 2 0 30s httpd httpd:2.4.18 run=httpd evan@k8s-master:~$ kubectl apply -f httpd.v3.yml --record deployment.extensions/httpd configured evan@k8s-master:~$ kubectl get deployment httpd -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR httpd 0/3 2 0 39s httpd httpd:2.4.18 run=httpd --record 的作用是将当前命令记录到 revision 记录中,这样我们就可以知道每个 revison 对应的是哪个配置文件。通过 kubectl rollout history deployment httpd 查看 revison 历史记录 evan@k8s-master:~$ kubectl rollout history deployment httpd deployment.extensions/httpd REVISION CHANGE-CAUSE 1 kubectl apply --filename=httpd.v1.yml --record=true 2 kubectl apply --filename=httpd.v3.yml --record=true 3 kubectl apply --filename=httpd.v2.yml --record=true evan@k8s-master:~$ kubectl get deployment httpd -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR httpd 2/3 2 2 3m9s httpd httpd:2.4.17 run=httpd evan@k8s-master:~$ kubectl rollout undo deployment httpd --to-revision=1 deployment.extensions/httpd rolled back evan@k8s-master:~$ kubectl get deployment httpd -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR httpd 2/3 3 2 3m36s httpd httpd:2.4.16 run=httpd evan@k8s-master:~$ kubectl rollout history deployment httpd deployment.extensions/httpd REVISION CHANGE-CAUSE 2 kubectl apply --filename=httpd.v3.yml --record=true 3 kubectl apply --filename=httpd.v2.yml --record=true 4 kubectl apply --filename=httpd.v1.yml --record=true