We ran our despatch scheduler as a StatefulSet so it could never run twice, and that kept it stopped for two hours
Our despatch scheduler batches orders into carrier collections, and it must never run as two copies at once, or the same orders go into two collections. So it runs in Kubernetes as a StatefulSet with one replica.
A Deployment's rolling update starts a new pod before the old one has gone. A StatefulSet promises at most one pod with a given name, which was exactly the guarantee we wanted.
The hung node
On a Tuesday in October, at ten past two, the virtual machine under that pod hung. The kernel stopped responding, but the hypervisor still reported the machine as running, so it stayed in the cluster.
Within a minute the node was NotReady. Five minutes later Kubernetes marked the scheduler's pod for deletion, as it does by default for pods on an unreachable node. Then nothing happened for the next hour and fifty minutes. Two afternoon collections left without the orders meant for them.
Why no replacement started
A pod on an unreachable node cannot be confirmed dead, because the only thing that could confirm it is the kubelet on that node. So the pod sat in Terminating.
A ReplicaSet would have started a replacement elsewhere straight away, since it does not count terminating pods. A StatefulSet will not create despatch-scheduler-0 again until the old despatch-scheduler-0 is gone from the API server, because the old one might still be running on a machine nobody can see.
The guarantee we chose the StatefulSet for was working perfectly. It had no way to tell a hung machine from a busy one.
Recovery and runbook
At four o'clock an engineer found the pod in Terminating, deleted it with --force, and the scheduler started on another node within a minute.
Force deletion is only safe if the old copy really is stopped, so our runbook now begins with fencing: power the virtual machine off through the cloud API and confirm it is off. Then we apply the node.kubernetes.io/out-of-service taint, stable since Kubernetes 1.28, which deletes the pods on that node and detaches its volumes without waiting for a kubelet that is never coming back.
We have alerts on:
- any pod in
Terminatingfor more than ten minutes, and - on any
StatefulSetwith fewer ready replicas than desired.
At most one, done safely, sometimes means none, and somebody has to be told when it does. - Sergey Shinder
Comments
No comments yet. Start the discussion.