If you have numerous replicas but want to roll out the release slowly, observe the application for any issues, and roll back your deployment if needed, you should use this strategy.
Let’s create an nginx deployment, nginx-ramped-slow-rollout.yaml, using the ramped slow rollout strategy:
…
spec:
replicas: 10
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
…
The manifest is very similar to the generic Deployment, except that it contains 10 replicas and a strategy section.
The strategy section contains the following:
- type: RollingUpdate
- rollingUpdate: The section describing rolling update attributes –maxSurge and maxUnavailable
Now, let’s apply the YAML file and wait for the deployment to completely roll out to 10 replicas using the following commands:
$ kubectl apply -f nginx-ramped-slow-rollout.yaml \
- kubectl rollout status deployment nginx deployment.apps/nginx configured
…
deployment “nginx” successfully rolled out
As we see, the pods have rolled out completely. Let’s now update the Deployment resource with a different nginx image version and see what we get using the following command:
$ kubectl set image deployment nginx nginx=nginx:1.16.1 \
- kubectl get replicaset -w deployment.apps/nginx image updated
NAME | DESIRED | CURRENT | READY | AGE |
nginx-6799fc88d8 | 10 | 10 | 10 | 3m51s |
nginx-6889dfccd5 | 1 | 1 | 0 | 0s |
nginx-6799fc88d8 | 9 | 10 | 10 | 4m |
………. .. .. . | ||||
nginx-6889dfccd5 | 8 | 8 | 8 | 47s |
nginx-6799fc88d8 | 2 | 3 | 3 | 4m38s |
nginx-6889dfccd5 | 9 | 9 | 8 | 47s |
nginx-6799fc88d8 | 2 | 2 | 2 | 4m38s |
nginx-6889dfccd5 | 9 | 9 | 9 | 51s |
nginx-6889dfccd5 | 10 | 9 | 9 | 51s |
nginx-6799fc88d8 | 1 | 2 | 2 | 4m42s |
nginx-6889dfccd5 | 10 | 10 | 10 | 55s |
nginx-6799fc88d8 | 0 | 1 | 1 | 4m46s |
nginx-6799fc88d8 | 0 | 0 | 0 | 4m46s |
So, we see two ReplicaSet resources here—nginx-6799fc88d8 and nginx-6889dfccd5. While the nginx-6799fc88d8 pod is slowly rolling down from 10 pods to 0, one at a time, simultaneously, the nginx-6889dfccd5 pod is slowly rolling up from 0 pods to 10. At any given time, the number of pods never exceeds 11. That is because maxSurge is set to 1, and maxUnavailable is 0. This is a slow rollout in action.
Tip
Ramped slow rollout is useful when we want to be cautious before we impact many users, but this strategy is extremely slow and may only suit some applications.
Let’s look at the best-effort controlled rollout strategy for a faster rollout without compromising application availability.