Every GET Was Fast and Every LIST Waited Three Seconds
For hours we asked the control plane how it was, and it said five milliseconds. We asked it the same way every time: fetch one object, time it. Meanwhile nothing could list anything in under three seconds, and the probe had no way to tell us, because the question it kept asking takes a road the problem does not touch.
The probe that said fine#
The incident ran about fourteen hours, and several things were wrong at once. This post is about the one we could not see.
From the outside it looked like this. kubectl get on a single named object
came back instantly. k9s, the terminal UI we use to look at the cluster, was
unusable: it sat and spun on every view. Pods that should have been running
were not. And the apiserver’s GET latency, which is the number we reached for
first, read about five milliseconds the whole time.
So we kept concluding the control plane was healthy and looked elsewhere. That was a reasonable inference from a fast GET. It was also wrong, and it stayed wrong for hours, because a fast GET does not tell you anything about a LIST. They are not the same request taking different amounts of time. In the apiserver we were running they go down different code paths, and only one of those paths waits.
Measure the verb that is slow#
The thing that broke it open was timing a LIST of something tiny. A list of the configmaps in one namespace — a handful of small objects — took about three seconds.
That is the tell. If a list is slow because it is big, a small one is fast. When a list of a handful of objects takes three seconds, the time is not being spent on the data. Something is waiting, and it waits a fixed time whatever you ask for.
The apiserver’s own metrics said the same thing once we asked them per verb and per stage. From our Prometheus, the day the problem was first written up:
| signal | value |
|---|---|
| LIST p99, services, pods, endpointslices, namespaces | about 5.0s |
apiserver_watch_cache_read_wait_seconds p99, same resources | 3.0s |
| consistent reads that fell back to storage | about 78% |
| datastore list call p99 | 57ms |
| apiserver CPU, every instance | 0.11 to 0.32 cores |
Everything that did work was fast. The datastore returned lists in tens of
milliseconds. The apiservers were nearly idle. The seconds were all in one
place: a histogram called read_wait, pinned at exactly three.
Where three seconds come from#
The apiserver keeps a watch cache: an in-memory copy of each resource type,
kept current by a watch on the datastore. Since Kubernetes 1.31 it has served
consistent lists from that cache, under a feature gate called
ConsistentListFromCache (KEP-2340). A LIST with no resourceVersion — what
kubectl get pods sends — is a consistent read: it must reflect every write
that happened before it.
The cache cannot simply assume it is current. So, in the 1.34 source, a consistent LIST does this:
- Ask the datastore for its current revision.
- Wait until the watch cache has seen that revision.
- While waiting, ask the datastore for a progress notification — a message on the watch stream that says “you are up to date as of revision N”, sent even when nothing the cache watches has changed.
The design document is plain about why step 3 exists: “For resources with infrequent changes, there is no guarantee that a watch event will be delivered at all.” A cache of something nobody is writing only learns it is current from a progress notification.
The wait is bounded. In watch_cache.go:
// blockTimeout determines how long we're willing to block the request
// to wait for a given resource version to be propagated to cache,
// before terminating request and returning Timeout error with retry
// after suggestion.
blockTimeout = 3 * time.Second
When it expires, the cache returns a “too large resource version” error, and
the code in front of it catches that and reads from the datastore directly:
“cache hasn’t caught up within the timeout period. Fall back to etcd.” It
counts the event in apiserver_watch_cache_consistent_read_total with
fallback="true".
So nothing was ever wrong with the answers. Every list that waited three seconds then returned correct, fresh data from a fast datastore. The whole cost was the wait, paid in full on every list of every resource whose cache could not prove it was current. That is also why the p99 read exactly 3.0: the wait gives up at three seconds, and the histogram’s top bucket ends at 3.
And GET? The same file that routes lists sends a GET with no
resourceVersion straight to storage: “If resourceVersion is not specified,
serve it from underlying storage.” It never consults the cache, so it never
waits. A GET probe is not a less sensitive version of a LIST probe. It
measures a different road.
Why our datastore was on that road at all#
Serving consistent lists from cache is only safe if the datastore really does answer progress requests, so the apiserver checks before it relies on it. It asks each datastore endpoint for its etcd version, and treats progress notification as supported from 3.4.31, or 3.5.13 within the 3.5 line.
We were not running etcd. We were running microk8s with k8s-dqlite, a dqlite-backed store that speaks the etcd API. The version it reports, in the release we ran, is a constant:
const emulatedEtcdVersion = "3.5.13"
Exactly the threshold. So the apiserver believed the datastore met the contract, took the cache path, asked for progress, and on our cluster did not get an answer that let it proceed within three seconds — often enough that most consistent reads fell back. Why the answer was late is a question about the datastore that we have not closed, and this post does not try to.
The switch that was taken away#
The obvious move was to turn the feature off and go back to reading lists from storage, which was fast. We tried it on one apiserver:
Error: cannot set feature gate ConsistentListFromCache to false, feature is locked to true
The gate’s history in the 1.34 source is three lines. Alpha and off in 1.28.
Beta and on by default from 1.31. GA in 1.34 with LockToDefault: true. A
locked gate cannot be set to anything else, and the apiserver refuses to start
rather than ignore the flag. Ours crash-looped until we took the line out.
We had first blamed the upgrade to 1.34 for the stall, because that is when we noticed it. Ten days of metrics history said otherwise: the read wait was already pinned at three seconds a week before the upgrade, and 94% of consistent reads fell back the day before it. The stall had been with us on 1.33, where the gate was on by default and could still be switched off. The upgrade did not introduce the problem. It removed the switch, which had been there to use for at least that week while we did not know we needed it.
Fine for me, dead for you#
There is one more property, and it is the one that made the failure so hard to agree about. Every apiserver keeps its own watch cache. The stall was per instance.
On one day of that week, two apiservers had a read wait pinned at 3.0 seconds while a third sat under one. Over the week, which ones were slow kept changing. Load did not explain which: per-node CPU and memory did not track the read wait, and on one day the fastest apiserver was the busiest node in the cluster.
Behind a load balancer, that means a client’s experience depends on which apiserver it happens to land on. One person’s tools are fine. Another’s hang. Both are reporting accurately. A health check pointed at the load-balanced address averages a stalled instance in with healthy ones, and reports something no single client actually experiences.
The evening it was at its worst, a probe of each apiserver in turn read 3041 to 3053ms for a LIST on every one of them, with GET at 40ms. There was no longer anywhere fast to go.
Two things helped while it lasted, and we offer them as what worked, not as a
cure. Pointing a client at one specific apiserver with --server makes it
usable when that instance is healthy. And restarting the k8s-dqlite member
on a node made that node’s apiserver fast again, and only that node’s; the
others stayed slow until they were restarted too. That
resets the condition. It does not explain it.
A probe that can see it#
This is the check we wish we had run in the first hour. It finds every
apiserver behind the kubernetes Service, then times one GET and one small
LIST against each, using kubectl -v=6 so that only the HTTP round trip is
counted and not kubectl’s own start-up. It reuses your current context’s
credentials, so it reads nothing you cannot already read. It needs kubectl
and jq, and an apiserver certificate that covers the addresses the Service
advertises, which it normally does.
#!/bin/sh
# Time a GET and a LIST against every apiserver behind the kubernetes Service.
# Only the HTTP round trip is counted (kubectl -v=6), not client start-up.
rt() {
kubectl --server "$1" get --raw "$2" -v=6 2>&1 >/dev/null |
sed -n 's/.*"Response" .* milliseconds=\([0-9]*\).*/\1/p'
}
ns=kube-system
get=/api/v1/namespaces/$ns/configmaps/kube-root-ca.crt
list=/api/v1/namespaces/$ns/configmaps
eps=$(kubectl get endpointslices -n default \
-l kubernetes.io/service-name=kubernetes -o jsonpath='{.items[0]}')
port=$(printf '%s' "$eps" | jq -r '.ports[0].port')
n=0
for ip in $(printf '%s' "$eps" | jq -r '.endpoints[].addresses[0]'); do
n=$((n + 1))
printf 'apiserver %d GET %4sms LIST %4sms\n' "$n" \
"$(rt "https://$ip:$port" "$get")" "$(rt "https://$ip:$port" "$list")"
done
Here it is on the same cluster today, on a quiet afternoon, months after the
incident (kubectl 1.36; the line format that sed matches is that client’s):
apiserver 1 GET 41ms LIST 353ms
apiserver 2 GET 56ms LIST 56ms
apiserver 3 GET 72ms LIST 355ms
apiserver 4 GET 67ms LIST 96ms
Each kubectl call opens a fresh connection, so both columns carry the same connection set-up and network time; it is the gap between them that matters. Even on a good day the shape is there: two instances answer a tiny LIST about as fast as a GET, and two take several times as long. On the evening of the incident, a probe like this read just over 3000 for the LIST on every instance.
The server-side view needs only Prometheus. Three queries: latency by verb, the read wait by apiserver, and how many consistent reads are giving up and falling back.
sum by (verb) (rate(apiserver_request_duration_seconds_sum{job="apiserver",verb=~"GET|LIST"}[1h]))
/ sum by (verb) (rate(apiserver_request_duration_seconds_count{job="apiserver",verb=~"GET|LIST"}[1h]))
histogram_quantile(0.99, sum by (instance, le) (rate(apiserver_watch_cache_read_wait_seconds_bucket{job="apiserver"}[1h])))
sum by (fallback) (rate(apiserver_watch_cache_consistent_read_total{job="apiserver"}[1h]))
Today, a blank line between the three results, and instance addresses replaced by numbers:
{verb="GET"} 0.005714802123997941
{verb="LIST"} 0.11145834534697846
{instance="1"} 0.575611111111111
{instance="2"} 1.1984337349397591
{instance="3"} 0.7139999999999992
{instance="4"} 0.9304999999999997
{fallback="false"} 1.7605042016806722
{fallback="true"} 0
An average GET of six milliseconds and an average LIST of a tenth of a second, a read wait p99 between about half a second and a little over one, and no fallbacks. On the day the problem was written up, the same read wait was 3.0 and most consistent reads were falling back.
The job="apiserver" matcher is not decoration on a single-binary
distribution. Ours serves one process-wide metrics registry on every port
Prometheus scrapes, so the apiserver’s series also turn up under the
kubelet’s, the scheduler’s and the others’ jobs. Unfiltered, the fallback rate
read 1.06 per second against a true 0.24.
What we would tell ourselves in July#
- A control-plane health check that only GETs tests the one path this failure cannot reach. Probe a LIST, of something small.
- Probe each apiserver, not the load-balanced address. A stalled instance averaged with healthy ones produces a number nobody is experiencing.
- Read latency by verb. One latency number for “the API” is the average of a road that waits and a road that does not.
- When a small list costs the same as a large one, the time is a wait, not work. Find the metric that measures the wait; the request-duration metric only tells you that it hurts.
- Read a release’s GA-locked gates as switches you are about to lose. If the behaviour behind one is already hurting you, the release before is the last place you can turn it off.
The fallbacks have since stopped. Between July and October the share of consistent reads falling back to storage went from most of them to none, and we have not established when or why. Over the last day the read wait p99 is around a second rather than three, and a services LIST has a p99 of about a second against a median of 24 milliseconds. We have not called that fixed. A stall that leaves without a cause can come back without one, and the only difference next time is that we will be timing the right verb.