Sub topic 10
Choosing an update strategy
This chapter assumes you can apply YAML manifests with kubectl, know how a Deployment rolls out new Pods, and have a DaemonSet like node-log-agent from the earlier chapters. When you change a DaemonSet's Pod template, the updateStrategy field decides how the running Pods are replaced.
The two strategies
A DaemonSet supports two update strategies.
| Strategy | What happens after a template change | Who replaces the Pods |
|---|---|---|
| `RollingUpdate` | The controller deletes old Pods and creates new ones, node by node | The controller |
| `OnDelete` | Nothing happens until you delete an old Pod | You |
RollingUpdate is the default for DaemonSets created with the apps/v1 API. The strategy only reacts to changes in .spec.template. Editing metadata or the replica-like status fields does not trigger a replacement.
RollingUpdate and maxUnavailable
With RollingUpdate, the controller removes the old Pod on a node and starts the new one there. It does this on several nodes at once, up to a limit you set with maxUnavailable. The value is either a number of nodes or a percentage of the nodes that should run the Pod. The default is 1.
spec:
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1A node counts as unavailable while its DaemonSet Pod is missing or not Ready. The controller moves to the next node only when the number of unavailable nodes drops below the limit. This means a new Pod that never becomes Ready blocks the rollout, which protects the rest of the cluster from a bad image.
Delete-before-create has a consequence. During the swap, the node has no agent at all for a short time. For a log collector, that gap can mean lost lines. For a network plugin, it can mean Pods on that node lose connectivity.
Tuning the speed
Pick maxUnavailable by asking how many nodes can safely lose the agent at the same time.
- A value of 1 is the safest. On a 200-node cluster it is also slow, because each node must become Ready before the next one starts.
- A percentage such as
10%scales with the cluster. Kubernetes rounds it up, so the result is never zero. - A larger number speeds up the rollout, and it widens the blast radius of a bad version.
Kubernetes also offers maxSurge for DaemonSets. It starts the new Pod on a node before the old one is removed, so the node is never without an agent. You can't combine it with a non-zero maxUnavailable, and it requires that two copies can run side by side. That fails if both copies bind the same host port or write the same host file.
spec:
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0OnDelete
With OnDelete, the controller never replaces Pods on its own. After you apply a new template, the old Pods keep running. A Pod is replaced only when you delete it, and the controller then creates a new one from the current template.
spec:
updateStrategy:
type: OnDeleteUse this when you must control the order, for example to update one node, check it by hand, and then continue. You can also tie each deletion to a maintenance window, a node drain, or a reboot. The cost is that the cluster can stay on mixed versions for as long as you let it, and kubectl rollout status does not report progress for this strategy in a useful way.
Choosing between them
For most node agents, RollingUpdate with a small maxUnavailable is the right default. Move to OnDelete only when you have a concrete reason to control each node yourself.
Common mistakes
- Setting
maxUnavailable: 0withoutmaxSurge. The API rejects this, because the rollout could never make progress. - Expecting an
OnDeleteDaemonSet to update afterkubectl apply. The Pods stay on the old template until you delete them. - Using a high
maxUnavailablewith an untested image. Several nodes lose their agent before the first failure shows up.
Exercise
A DaemonSet runs a monitoring agent that binds host port 9100. You want every node to keep an agent running during updates. Can you use maxSurge, and why?
Show answer
No. During a surge, the old and new Pods run on the same node at once, and both would try to bind host port 9100. The new Pod would fail to start and stall the rollout. Use RollingUpdate with maxUnavailable: 1 instead, and accept a short gap on each node.
Exercise
You apply a new image to a DaemonSet that uses OnDelete, and no Pods change. What do you do to update the Pod on node worker-2?
Show answer
Find the DaemonSet Pod running on worker-2 with kubectl get pods -o wide, then delete it with kubectl delete pod. The controller recreates it from the new template.