Kubernetes - Rolling Update Deployment and MaxSurge MaxUnavailable
Max Unavailable
.spec.strategy.rollingUpdate.maxUnavailable is an optional field that specifies the maximum number of Pods that can be unavailable during the update process. The value can be an absolute number (for example, 5) or a percentage of desired Pods (for example, 10%). The absolute number is calculated from percentage by rounding down. The value cannot be 0 if .spec.strategy.rollingUpdate.maxSurge is 0. The default value is 25%.
For example, when this value is set to 30%, the old ReplicaSet can be scaled down to 70% of desired Pods immediately when the rolling update starts. Once new Pods are ready, old ReplicaSet can be scaled down further, followed by scaling up the new ReplicaSet, ensuring that the total number of Pods available at all times during the update is at least 70% of the desired Pods.
Max Surge
.spec.strategy.rollingUpdate.maxSurge is an optional field that specifies the maximum number of Pods that can be created over the desired number of Pods. The value can be an absolute number (for example, 5) or a percentage of desired Pods (for example, 10%). The value cannot be 0 if MaxUnavailable is 0. The absolute number is calculated from the percentage by rounding up. The default value is 25%.
For example, when this value is set to 30%, the new ReplicaSet can be scaled up immediately when the rolling update starts, such that the total number of old and new Pods does not exceed 130% of desired Pods. Once old Pods have been killed, the new ReplicaSet can be scaled up further, ensuring that the total number of Pods running at any time during the update is at most 130% of desired Pods.
N=maxsurge-maxunavailable-ns
k create ns $N
k -n $N create deployment rolling-update-deployment --image nginx:1.14.2 --port 80 --replicas 10
k -n $N rollout status deployment rolling-update-deployment
k -n $N rollout history deployment rolling-update-deployment
# Update Image
k -n $N set image deployment rolling-update-deployment nginx=nginx:1.16.1
k -n $N rollout status deployment rolling-update-deployment
k -n $N rollout history deployment rolling-update-deployment
# UPDATE THE ROLLING STRATEGY
# maxSurge: 50%
# maxUnavailable: 3
k -n $N edit deploy rolling-update-deployment
# TYPO MISTAKE IN IMAGE LABEL
k -n $N set image deployment rolling-update-deployment nginx=nginx:1.220
k -n $N rollout status deployment rolling-update-deployment
k -n $N get rs # CHECK REPLICASETS
k -n $N get po # 15 PODS
k -n $N describe deploy # CHECK REPLICAS
k -n $N rollout history deployment rolling-update-deployment
# 1 is the oldest/earliest - GET IMAGE FOR REVISION 3
k -n $N rollout history deployment rolling-update-deployment --revision=3
# GO BACK TO PREVIOUS VERSION
k -n $N rollout undo deployment rolling-update-deployment
# OR
# k -n $N rollout undo deployment rolling-update-deployment --to-revision=2
# CHECK HISTORY
k -n $N rollout history deployment rolling-update-deployment
# CONFIRM
k -n $N get deploy rolling-update-deployment
# SCALE
k -n $N scale deployment rolling-update-deployment --replicas=15
k -n $N get deploy rolling-update-deployment
# CLEANUP
N=maxsurge-maxunavailable-ns
k -n $N delete deploy rolling-update-deployment
k delete ns $N
THANKS
FOR
WATCHING
Kubernetes-Rolling-Deployment-MaxSurge-MaxUnavailable
By Deepak Dubey
Kubernetes-Rolling-Deployment-MaxSurge-MaxUnavailable
- 64