How does rolling update work in kubernetes

3/15/2018

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

-- ambikanair
kubernetes

2 Answers

3/15/2018

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.

-- dippynark
Source: StackOverflow

3/15/2018

From design document:

For the purposes of this example, assume that we are rolling from foo to foo-next where the only change is an image update from v1 to v2

If the user doesn't specify a foo-next 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 and foo-next do not exist:

    • Exit, and indicate an error to the user, that the specified controller doesn't exist.
  • If foo exists, but foo-next does not:

    • Create foo-next populate it with the v2 image, set desired-replicas to foo.Spec.Replicas
  • If foo-next exists, but foo does not:

    • Assume that we are in the rename phase.

    • Goto Rename

  • If both foo and foo-next exist:

    • Assume that we are in a partial rollout

    • If foo-next is missing the desired-replicas annotation

      • Populate the desired-replicas annotation to foo-next using the current size of foo
  • Goto Rollout

Rollout

  • While size of foo-next < desired-replicas annotation on foo-next

    • increase size of foo-next
    • if size of foo > 0 decrease size of foo
  • Goto Rename

Rename

  • delete foo

  • create foo that is identical to foo-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 and foo both exist

    • Set desired-replicas annotation on foo to match the annotation on foo-next

    • Goto Rollout with foo and foo-next trading places.

-- Anton Kostenko
Source: StackOverflow