Best-effort controlled rollout helps you roll out your deployment on a best-effort basis, and you can use it to roll out your release faster and ensure that your application is available. It can also help with applications that do not tolerate more than a certain number of replicas at a given point.
We will set maxSurge to 0 and maxUnavailable to any percentage we find suitable for remaining unavailable at a given time to implement this. It can be specified using the number of pods or as a percentage.
Tip
Using a percentage is a better option since, with this, you don’t have to recalculate your maxUnavailable parameter if the replicas change.
Let’s look at the manifest—nginx-best-effort-controlled-rollout.yaml:
…
spec:
replicas: 10
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 0
maxUnavailable: 25%
…
Let’s now apply the YAML file and see what we get:
$ kubectl apply -f nginx-best-effort-controlled-rollout.yaml \
- kubectl get replicaset -w deployment.apps/nginx configured
NAME | DESIRED | CURRENT | READY | AGE |
nginx-6799fc88d8 | 2 | 0 | 0 | 20m |
nginx-6889dfccd5 | 8 | 8 | 8 | 16m |
nginx-6799fc88d8 | 2 | 2 | 1 | 20m |
nginx-6889dfccd5 | 7 | 8 | 8 | 16m |
……………. | ||||
nginx-6889dfccd5 | 1 | 1 | 1 | 16m |
nginx-6799fc88d8 | 9 | 9 | 8 | 20m |
nginx-6889dfccd5 | 0 | 1 | 1 | 16m |
nginx-6799fc88d8 | 10 | 9 | 8 | 20m |
nginx-6889dfccd5 | 0 | 0 | 0 | 16m |
nginx-6799fc88d8 | 10 | 10 | 10 | 20m |
So, we see the ReplicaSet resource rolling out such that the total pods are at most 10 at any point, and the total unavailable pods are never more than 25%. You may also notice that instead of creating a new ReplicaSet resource, the Deployment resource uses an old ReplicaSet resource containing the nginx:latest image. Remember when I said the old ReplicaSet resource is not deleted when you update a Deployment resource?
Deployment resources on their own are great ways of scheduling and managing pods. However, we have overlooked an essential part of running containers in Kubernetes—exposing them to the internal or external world. Kubernetes provides several resources to help expose your workloads appropriately— primarily, Service and Ingress resources. Let’s have a look at these in the next section.