Why My Kubernetes Control-Plane Node Kept Freezing

A three-member Kubernetes control plane is built to survive the loss of one member. Mine couldn't. The answer was hidden in a file header, and it was five times larger than it looked.

The command was meant to be routine. My Kubernetes cluster had three
machines voting on its state, and I wanted one fewer. A quorum of three can
lose a member and keep going; that is the entire point of having three. I
typed the command that removes a member, pressed Enter, and watched the API
server stop answering.

Later that evening I tried again, more carefully. The same thing happened.

The cluster runs MicroK8s, which keeps its state not in etcd but in
dqlite: SQLite, replicated across machines with the Raft consensus
protocol. Two of the three voters sit in my home; the third is a small
virtual machine in the cloud, reached over a VPN. The home machines were
about to move to a new address, and the plan was simple: make the cloud
machine the cluster's only brain, so that unplugging the house would no
longer threaten the whole system.

Instead, removing a single voter was enough to take the control plane down.
Raft is not supposed to behave that way. Something in my cluster was
quietly breaking the arithmetic.

A voter that did not vote

The first clue came from the Raft logs themselves. Each voter keeps an
append-only log of changes, and in a healthy cluster their positions march
forward together. Two of mine did. The cloud machine's had simply stopped.

It was still listed as a voter. It answered when spoken to. But it was not
accepting new entries. In effect, my "three-voter" cluster had been a
two-voter cluster for some time, and removing one of the remaining two left
a lone machine that could not form a majority.

Two further observations shaped everything that followed. The cloud voter
had frozen immediately after installing a snapshot: the compressed copy of
the database that a Raft leader sends to a member that has fallen too far
behind to catch up entry by entry. And by the next morning, it had
recovered. No one had restarted it. The leader had not changed. The cluster
was still in the same Raft term.

A machine that heals itself is not broken. Whatever was wrong had to do with
catching up.

The theories that died

Investigations like this proceed by elimination, and several suspects fell
quickly. Firewall and overlay-network rules were letting traffic through.
The API server's watch-cache settings, a known source of trouble on this
cluster, had nothing to do with replication. A hidden packet-size limit on
the VPN, known as an MTU black hole, was ruled out by sending large pings
that arrived intact. And the cloud machine was not a non-voting member in
disguise; the membership list was unambiguous.

I worked through much of this with Claude Code, an AI coding assistant. It
ran the read-only diagnostics and proposed theories, and some of them, like
the MTU one, did not survive their first test. Every actual change went into
files under version control, and I applied them myself.

Reproducing the crime

If the problem lived in catching up, it should be possible to cause it on
purpose.

A brief restart of the cloud voter produced nothing interesting: it rejoined
and caught up through ordinary log replication within seconds. That result
mattered, because it showed the node itself was fine.

The second experiment was crueler. Raft leaders keep only a limited tail of
recent log entries, about ten minutes' worth on my cluster. I stopped the
cloud voter for longer than that, so that when it returned the leader would
have no choice but to send a full snapshot. Then I turned on dqlite's debug
tracing, which is controlled by an environment variable,
LIBDQLITE_TRACE=1, and started it again.

The trace read like a phone call in which only one side can hear:

recvAppendEntries         from:<leader> n_entries:0
checkLogMatchingProperty  no entry at index <N> -> reject
...
tickFollower              convert to candidate and start new election
recvRequestVoteResult     vote_granted:0 pre_vote:1

The returning voter received the leader's heartbeats and correctly rejected
them, which in Raft's vocabulary means: I am behind; send me a snapshot.
Then the heartbeats stopped. After a few seconds of silence, the follower
concluded that the leader had died and began calling for elections, roughly
every 20 seconds. The other home voter, which could still hear the leader
perfectly well, refused each request, as it should.

The follower was not ignoring the leader. It simply was not hearing from it.

Five times bigger than it looked

The answer was in the network. On the leader, the Linux tool ss can show
the state of a single TCP connection, and the connection to the cloud voter
was anything but idle. The leader was transmitting continuously at a few
megabits per second, the speed of a home upload link. Its send queue stayed
full. Packets were being retransmitted. Round-trip latency on the link,
normally about 15 milliseconds, had swollen to roughly 340, the signature of
a saturated connection with its buffers full, a condition known as
bufferbloat.

That was strange, because the snapshot file on disk was only about 22
megabytes, and the leader had already sent several times that amount.

The explanation was hiding in the first bytes of the file. dqlite compresses
snapshots on disk with LZ4, and an LZ4 frame header can record the original,
uncompressed size. It did: about 111 megabytes. Compression saves disk
space, but the leader sends the snapshot uncompressed, so 111 megabytes is
what has to cross the network.

The arithmetic was unforgiving. At a few megabits per second, one copy takes
minutes to transmit. By default, Raft gives a snapshot installation about 30
seconds to complete. When the time ran out, the leader concluded the attempt
had failed, and began again. And again.

Worse, Raft's heartbeats travel on the same TCP connection. They waited in
line behind tens of megabytes of snapshot data, so from the follower's point
of view the leader had gone silent. That explained the elections.

In about half an hour, the leader sent roughly 2.5 gigabytes to deliver a
snapshot that never fully arrived. The mysterious overnight recovery had been
luck: at some point, one copy got through between attempts.

Would your cluster do this?

If you run MicroK8s or dqlite, this read-only check, run on a control-plane
node, estimates how long your snapshot takes to cross a given link:

B=/var/snap/microk8s/current/var/kubernetes/backend
f=$(sudo ls -t "$B" | grep -E '^snapshot-[0-9-]+$' | head -1)
size=$(sudo head -c 14 "$B/$f" | python3 -c 'import sys,struct
h=sys.stdin.buffer.read()
ok = h[:4] == b"\x04\x22\x4d\x18" and h[4] & 0x08
print(struct.unpack("<Q", h[6:14])[0] if ok else 0)')
mbit=10   # your real upload speed, Mbit/s
echo "on disk: $(( $(sudo stat -c %s "$B/$f") / 1000000 )) MB, on the wire: $((size / 1000000)) MB, ~$((size * 8 / 1000000 / mbit)) s at $mbit Mbit/s (default install timeout: 30 s)"

LZ4 frames begin with the bytes 04 22 4D 18. If bit 0x08 of the next
byte is set, eight bytes later sits the uncompressed size. On my cluster the
script prints 22 megabytes on disk, 111 on the wire, and about 88 seconds at
10 megabits per second: nearly three times the timeout. Curious readers can
reproduce the loop with three dqlite nodes, a tc netem rate limit on one of
them, and a long enough outage.

Moving the brain by hand

The lesson was clear: no voter should ever have to catch up over that link
again. So the migration happened offline. I stopped the voters, copied the
database to the cloud machine once, as an ordinary file verified by
checksum, and used dqlite's .reconfigure command, the same path MicroK8s
documents for restoring a lost quorum, to turn the copy into a cluster with a
single voter. I rehearsed the whole procedure on a scratch copy first.

Reading the MicroK8s source code before touching anything turned up four
traps.

  1. Split-brain. The two old voters still believed in a three-member
    cluster, so together they formed a majority and could have elected a
    rival leader. They had to be locked out before the new one started.
  2. Kubelets kill pods. A kubelet that connects to an empty, freshly
    reset API server stops every pod that server doesn't list. A worker must
    never see one.
  3. A proxy that can't find its way. Workers discover control-plane
    endpoints through the existing control planes, so once those were gone
    they could never learn about the new one. Their proxy had to be pointed
    at it by hand.
  4. The eviction clock. A node that stops reporting has its pods evicted
    after a few minutes, so the grace period had to be stretched for the
    duration.

The cutover took about 13 minutes without an API server. No pods were
replaced, and the blog stayed online throughout, because public traffic does
not pass through the Kubernetes API.

What the cluster taught me

Measure the bytes on the wire, not the bytes on disk. Raft across a slow,
asymmetric link does not fail loudly; it fails as a member that is present
but silent. A health check that says "ready" is not proof of health. Even
keepalives can mislead: midway through planning, one of my VPN tunnels
turned out to have been dead for an hour, stuck on a broken network-address
mapping that its own keepalive packets had kept from expiring.

And risky migrations deserve to be done offline, rehearsed, with a written
point of no return.

The cluster now has one control plane, in the cloud. It is the boring
arrangement. That is the point.

Subscribe to Dr. Jawad Tahir

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe