Docker Kubernetes 容器更新与回滚
Docker Kubernetes 容器更新与回滚
环境:
- 系统:Centos 7.4 x64
- Docker版本:18.09.0
- Kubernetes版本:v1.8
- 管理节点:192.168.1.79
- 工作节点:192.168.1.78
- 工作节点:192.168.1.77
创建环境:
- 1、Deployment名称:nginx-deployment
- 2、pods副本数为:3
- 3、image镜像:nginx1.9
更新升级
方案一:管理节点:滚动升级镜像。
kubectl set image deployment nginx-deployment nginx=nginx:1.11
kubectl set image 资源类型/资源名称 容器名称=镜像版本
方案二:管理节点:修改原yaml配置文件重新加载完成滚动升级
kubectl apply -f nginx-deployment.yaml
管理节点:查看升级情况
命令:kubectl describe deployment nginx-deployment # 镜像已更新 Image: nginx:1.11 Type Reason Age From Message ---- ------ ---- ---- ------- # 扩容版本 Normal ScalingReplicaSet 24m deployment-controller Scaled up replica set nginx-deployment-845cfc7fb9 to 3 Normal ScalingReplicaSet 49s deployment-controller Scaled up replica set nginx-deployment-7ff5df4cfb to 1 # 缩容版本 Normal ScalingReplicaSet 34s deployment-controller Scaled down replica set nginx-deployment-845cfc7fb9 to 2 # 扩容版本 Normal ScalingReplicaSet 34s deployment-controller Scaled up replica set nginx-deployment-7ff5df4cfb to 2 # 缩容版本 Normal ScalingReplicaSet 18s deployment-controller Scaled down replica set nginx-deployment-845cfc7fb9 to 1 # 扩容版本 Normal ScalingReplicaSet 18s deployment-controller Scaled up replica set nginx-deployment-7ff5df4cfb to 3 # 缩容版本 Normal ScalingReplicaSet 15s deployment-controller Scaled down replica set nginx-deployment-845cfc7fb9 to 0
命令:kubectl rollout status deployment/nginx-deployment Waiting for rollout to finish: 1 out of 3 new replicas have been updated... Waiting for rollout to finish: 1 out of 3 new replicas have been updated... Waiting for rollout to finish: 1 out of 3 new replicas have been updated... Waiting for rollout to finish: 2 out of 3 new replicas have been updated... Waiting for rollout to finish: 2 out of 3 new replicas have been updated... Waiting for rollout to finish: 2 out of 3 new replicas have been updated... Waiting for rollout to finish: 1 old replicas are pending termination... Waiting for rollout to finish: 1 old replicas are pending termination... deployment "nginx-deployment" successfully rolled out
命令:kubectl rollout history deployment/nginx-deployment deployments "nginx-deployment" REVISION CHANGE-CAUSE 1 <none> 2 <none>
命令:kubectl rollout history deployment/nginx-deployment --revision=1 deployments "nginx-deployment" with revision #1 Pod Template: Labels: app=nginx pod-template-hash=4017973965 Containers: nginx: Image: nginx:1.10 Port: 80/TCP Environment: <none> Mounts: <none> Volumes: <none>
版本回滚
管理节点:回滚到上一个版本
kubectl rollout undo deployment nginx-deployment
kubectl rollout undo 资源类型 资源名称
管理节点:指定版本回滚
kubectl rollout undo deployment/nginx-deployment --to-revision=3
kubectl rollout undo 资源类型 资源名称 --to-revision=版本号
注:kubectl rollout history 资源类型 资源名称 查看的版本号。
管理节点:查看回滚情况
命令:kubectl rollout history deployment/nginx-deployment deployments "nginx-deployment" REVISION CHANGE-CAUSE 1 <none> 2 <none> 4 <none> 5 <none> 注:将还原版本覆盖,并生成新的版本号。