ReplicaSet 进行逐个调整。最后,新的 ReplicaSet 运行了 3 个新版本 Pod 副本,旧的 ReplicaSet 副本数量则缩
减为0。如图所示。
下面列出 Deployment nginx-deployment 的详细事件信息:
[root@master cha3]# kubectl describe deployments/nginx-deployment
Name: nginx-deployment
Namespace: default
CreationTimestamp: Mon, 10 Jul 202320:20:12 +0800
Labels: <none>
Annotations: deployment.kubernetes.io/revision: 2
Selector: app=nginx-deployment
Replicas: 3 desired |3 updated |3 total |3 available |0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=nginx-deployment
Containers:
nginx:
Image: nginx:1.9.1
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-deployment-76478869c8 (3/3 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 10m deployment-controller Scaled up replica set nginx-deployment-5c5f6c4496 to 3
Normal ScalingReplicaSet 9m6s deployment-controller Scaled up replica set nginx-deployment-76478869c8 to 1
Normal ScalingReplicaSet 9m4s deployment-controller Scaled down replica set nginx-deployment-5c5f6c4496 to 2
Normal ScalingReplicaSet 9m4s deployment-controller Scaled up replica set nginx-deployment-76478869c8 to 2
Normal ScalingReplicaSet 9m2s deployment-controller Scaled down replica set nginx-deployment-5c5f6c4496 to 1
Normal ScalingReplicaSet 9m2s deployment-controller Scaled up replica set nginx-deployment-76478869c8 to 3
Normal ScalingReplicaSet 9m deployment-controller Scaled down replica set nginx-deployment-5c5f6c4496 to 0
运行 kubectl get rs 命令,查看两个 ReplicaSet 的最终状态:
[root@master cha3]# kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-deployment-5c5f6c4496 000 11m
nginx-deployment-76478869c8 333 9m42s
在整个升级的过程中,系统会保证至少有两个 Pod 可用,并且最多同时运行 4 个 Pod,这是 Deployment 通过复
杂的算法完成的。Deployment 需要确保在整个更新过程中只有一定数量的 Pod 可能处于不可用状态。在默认情
况下,Deployment 确保可用的 Pod 总数至少为所需的副本数量 DESIRED 减1,也就是最多1个不可用
maxUnavailable=1。Deployment 还需要确保在整个更新过程中 Pod 的总数量不会超过所需的副本数量太多。在
默认情况下,Deployment 确保 Pod 的总数最多比所需的 Pod 数多1个,也就是最多1个浪涌值 maxSurge=1。
# deployments.apps "nginx-deployment" was not valid:# * spec.template.metadata.labels: Invalid value: map[string]string{"app":"nginx"}: `selector` does not match template `labels`
# 现在的环境[root@master cha3]# kubectl create -f 034-nginx-deployment.yaml
deployment.apps/nginx-deployment created
[root@master cha3]# kubectl get rs,deploy,pod
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx-deployment-5c5f6c4496 333 22s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx-deployment 3/3 33 22s
NAME READY STATUS RESTARTS AGE
pod/nginx-deployment-5c5f6c4496-22gfk 1/1 Running 0 22s
pod/nginx-deployment-5c5f6c4496-4ddxd 1/1 Running 0 22s
pod/nginx-deployment-5c5f6c4496-rkqzq 1/1 Running 0 22s
[root@master cha3]# kubectl set image deployment/nginx-deployment nginx=nginx:1.91
deployment.apps/nginx-deployment image updated
则这时 Deployment 的部署过程会卡住:
[root@master cha3]# kubectl rollout status deployment/nginx-deployment
Waiting for deployment "nginx-deployment" rollout to finish: 1 out of 3 new replicas have been updated...
[root@master cha3]# kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 3/3 33 8m43s
[root@master cha3]# kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-deployment-5c5f6c4496 333 9m22s
nginx-deployment-77f88687b6 000 8m43s
[root@master cha3]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-deployment-5c5f6c4496-22gfk 1/1 Running 0 9m30s
nginx-deployment-5c5f6c4496-4ddxd 1/1 Running 0 9m30s
nginx-deployment-5c5f6c4496-rkqzq 1/1 Running 0 9m30s
[root@master cha3]# kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-deployment-5c5f6c4496 000 11m
nginx-deployment-77f88687b6 000 11m
nginx-deployment-889d8b75d 333 13s
查看 Deployment 的事件信息,可以看到 Deployment 完成了更新:
[root@master cha3]# kubectl describe deployment/nginx-deployment
Name: nginx-deployment
Namespace: default
CreationTimestamp: Mon, 10 Jul 202321:43:07 +0800
Labels: <none>
Annotations: deployment.kubernetes.io/revision: 4
Selector: app=nginx-deployment
Replicas: 3 desired |3 updated |3 total |3 available |0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=nginx-deployment
Containers:
nginx:
Image: nginx:1.9.1
Port: 80/TCP
Host Port: 0/TCP
Limits:
cpu: 200m
memory: 512Mi
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-deployment-889d8b75d (3/3 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 12m deployment-controller Scaled up replica set nginx-deployment-5c5f6c4496 to 3
Normal ScalingReplicaSet 11m deployment-controller Scaled up replica set nginx-deployment-77f88687b6 to 1
Normal ScalingReplicaSet 8m16s deployment-controller Scaled down replica set nginx-deployment-77f88687b6 to 0
Normal ScalingReplicaSet 60s deployment-controller Scaled up replica set nginx-deployment-889d8b75d to 1
Normal ScalingReplicaSet 59s deployment-controller Scaled down replica set nginx-deployment-5c5f6c4496 to 2
Normal ScalingReplicaSet 59s deployment-controller Scaled up replica set nginx-deployment-889d8b75d to 2
Normal ScalingReplicaSet 57s deployment-controller Scaled down replica set nginx-deployment-5c5f6c4496 to 1
Normal ScalingReplicaSet 57s deployment-controller Scaled up replica set nginx-deployment-889d8b75d to 3
Normal ScalingReplicaSet 55s deployment-controller Scaled down replica set nginx-deployment-5c5f6c4496 to 0