How does rolling update work in kubernetes internally. Is it one pod after another. will the update get stuck or takes time if one of the pod goes to error state during the update
There are two fields (maxSurge
and maxUnavailable
) on the deployment spec that you can use to control how a rolling update is performed. kubectl explain deployment.spec.strategy.rollingUpdate
will give you full details about these fields, but in short they determine how many pods you can go over your replica count and how many pods can become unavailable respectively during a rolling update.
For the maxUnavailable
field to work properly, it's important to configure readiness probes on your pod template properly.
More information can be found here.
From design document:
For the purposes of this example, assume that we are rolling from
foo
tofoo-next
where the only change is an image update fromv1
tov2
If the user doesn't specify a
foo-nex
t name, then it is either discovered from the update-partner annotation on foo. If that annotation doesn't exist, then foo-next is synthesized using the pattern<controller-name>-<hash-of-next-controller-JSON>
Initialization
If
foo
andfoo-next
do not exist:
- Exit, and indicate an error to the user, that the specified controller doesn't exist.
If
foo
exists, butfoo-next
does not:
- Create
foo-next
populate it with thev2
image, setdesired-replicas
tofoo.Spec.Replicas
If
foo-next
exists, butfoo
does not:
Assume that we are in the rename phase.
Goto Rename
If both
foo
andfoo-next
exist:
Assume that we are in a partial rollout
If
foo-next
is missing thedesired-replicas
annotation
- Populate the
desired-replicas
annotation tofoo-next
using the current size offoo
Goto Rollout
Rollout
While size of
foo-next
<desired-replicas
annotation onfoo-next
- increase size of
foo-next
- if size of
foo
> 0 decrease size offoo
Goto Rename
Rename
delete
foo
create
foo
that is identical tofoo-next
delete
foo-next
Abort
If
foo-next
doesn't exist
- Exit and indicate to the user that they may want to simply do a new rollout with the old version
If
foo
doesn't exist
- Exit and indicate not found to the user
Otherwise,
foo-next
andfoo
both exist
Set
desired-replica
s annotation onfoo
to match the annotation onfoo-next
Goto Rollout with
foo
andfoo-next
trading places.