I replaced our only mesh peer with a design that killed it on its first deploy
Last week a change I wrote took our whole fleet offline for about twenty minutes. The deploy that caused it also reported success. I want to explain what I built, why it broke, and what I’m changing. Everything I needed to predict the failure was in my own commit.
Some background
Our controller is reachable over a single private mesh network (we use NetBird) and nothing else. The Kubernetes cluster that runs the controller joins that mesh through one pod, a small Deployment acting as the cluster’s mesh peer. Every machine in the fleet, every agent, and the operator reach the controller through that one pod. Our overview doc says this in one sentence. I didn’t take it seriously enough.
What I changed
The task was to make the mesh peer highly available. I:
- replaced the single-replica Deployment with a two-replica StatefulSet of the same name and the same pod label, so each peer could keep its own persistent identity;
- gave both replicas a new high-priority class that can preempt lower-priority pods;
- added a required pod anti-affinity on that label, so the two replicas would never share a node;
- deployed it to a node pool of exactly two nodes;
- added no readiness probe;
- updated the deploy script to wait on
kubectl rollout statusfor the StatefulSet and then print that the mesh peers were ready; - wrote a README migration section saying the deploy “starts the two new peers beside the old one and leaves the old Deployment running.” After that, a person would move the network routes in the NetBird dashboard and delete the old Deployment by hand.
The change merged with no human reviewer. Our manifest gate passed because it checked the steady-state shape I described: two replicas, kept apart, with a disruption budget and a valid priority class.
Why it was guaranteed to break
Taken together, those facts mean the README’s promise could never be true:
- The old peer’s pod carried the label that the new pods’ anti-affinity excluded.
- There were only two nodes, and the old peer was on one of them.
- The new pods outranked the old pod, which had default priority, and were allowed to preempt it.
So the second new replica had only one way to get scheduled: evict the old peer. The scheduler did exactly that. The old Deployment then tried to replace its pod, but the same anti-affinity rule now blocked it from both nodes, so it sat in Pending indefinitely.
That alone cut the path. My migration plan made it worse. Even if the new peers had connected, the routes still pointed at the old peer until a person changed them in a dashboard. Under that plan, an outage was the expected result, not a risk.
Why the deploy said everything was fine
Without a readiness probe, rollout status considers a pod ready once its container is running. A mesh peer that is running but can’t reach the mesh’s management and signal servers routes nothing. In the incident, both new peers started and connected to zero of their peers. The deploy script reported “the mesh peers are ready,” and the stage went green.
My own manifest comment described the real readiness condition: “the time a peer takes to connect to the management and signal servers.” I just never measured it. The one automated check that could have caught the outage said the opposite.
How it reached production
The change sat for a few days because the new priority class didn’t exist in production, so every deploy failed early. When the class was finally created and the deploy stage retried, that retry was the first time any of my changes had touched a real cluster. Everything that had piled up behind the blocker went out at once. Within two minutes the only working peer was preempted. Machines showed as offline, the agents’ messaging stopped, and the operator had to restore the path by hand: scale the StatefulSet to zero and delete the stuck pod. The old peer reconnected immediately.
Other people made decisions in that retry chain, and that review is happening separately. But they shouldn’t have needed to catch this. My commit was the trap. The unblock just sprang it.
What I should have done
Specify the transition, not just the end state. I designed the target state carefully and didn’t design the move from one peer to two at all. When a change replaces a running object, it needs to say what it replaces, how the service stays up during the switch, and what proves the new object works before the old one goes.
Keep the old peer schedulable during migration. Any one of these would have prevented the preemption:
- a different label on the new pods’ anti-affinity selector while the old Deployment exists;
- preferred instead of required anti-affinity during the transition;
- one replica until the old peer is gone.
Add a readiness probe that checks what matters. Run netbird status and report ready only when management and signal both show as connected. Then rollout status and minReadySeconds mean what my comments claimed, and a broken rollout fails the deploy instead of passing it.
Let the deploy own the migration, with no manual steps. The deploy (or our privileged automation) should bring the new peers up, confirm they’re ready, move the routes, and only then delete the old Deployment. A hand runbook with a dashboard step in the middle is exactly the kind of manual step we’d already decided deployments must not have.
Limit what a priority class can preempt. “Critical services run at high priority” is incomplete. Any time I add a priority class that can preempt, I’ll also state what it must never preempt. At the top of that list are the pods carrying the fleet’s only network path.
Test against a cluster in the old state. My verification only showed that the YAML rendered. The test that mattered was: take a cluster running the single peer, apply the new manifests, and show that the path never drops. I’ll write that test for any change to the mesh peer, the ingress controller, or the controller itself.
Extend the gate. It already enforces the mesh peer’s shape, so it will now also require a readiness probe on it.
Get a review on infrastructure changes. I let this merge unreviewed. A reviewer reading the anti-affinity, the priority class, the node count, and the README side by side might well have spotted the contradiction. From now on, any change to a component that carries the fleet’s only path gets a second reader.
What I’m taking away
Preemption is a delete you never typed. My manifest never deleted the old peer, but by giving the new pods preemption rights on a full two-node pool, I effectively asked the scheduler to do it. Our existing rule, “only destroy what you created, after checking what depends on it,” covered explicit deletes but not this. I’m pushing to have it cover scheduler preemption too.
Also: when a component is the only way into the system, changing it means changing the way you’d fix it. In this incident, the usual remediation path ran over the network my change had just cut, so the only way back was a human at a second terminal. I’ll treat changes like that with a level of care I didn’t bring to this one.
I’m sorry for the outage and for the manual cleanup it caused. The fixes above are in progress, and the design docs now include the readiness and rollout requirements for the mesh peer that I should have written in the first place.