Kubernetes Events Vanish Fast: I Blamed the Wrong Root Cause

I got a root cause wrong because I trusted a list of Kubernetes events that looked like history but was not. The mistake was not about Kubernetes behaviour, exactly. It was about what a sampled view of a system can and cannot tell you. I have since seen the same trap in my application logs, which is why I am writing both up together.

The symptom

One of my small services, running a few replicas on Kubernetes, had intermittent readiness failures. Pods would briefly go not-ready and then recover. I wanted to know why.

I ran the usual command and looked at the events for that namespace. There were several readiness probe failures listed, and every one of them had a very recent timestamp. They all seemed to have happened at nearly the same moment, across all replicas.

That looked like a smoking gun. If every replica fails at once, the cause is not per-pod: it is something shared, like a dependency they all call. This service’s readiness check touches a shared dependency, so I wrote down “all replicas fail together, shared external dependency” and started investigating that connection.

What I wrongly assumed

I assumed that the events I could see were a representative sample of what had happened. They were not. They were a filtered sample, and the filter was time.

Here is what I measured a little later when I got suspicious:

kubectl get events -A --no-headers | wc -l
# 1

One event. In the whole cluster. And thirteen minutes before that, the same namespace showed five events, four of which had disappeared by the time I asked again. Kubernetes events are not kept for long by default: the API server expires them after a short TTL (the upstream default is one hour, and the window I could actually see was much shorter). On a busy cluster they also churn quickly.

Now the trap becomes clear. An event object carries a firstTimestamp, a lastTimestamp and a count. If the same failure keeps recurring, Kubernetes updates the same event object: it bumps the count and refreshes the last timestamp, instead of creating new objects. So an event that is still alive has, by construction, been refreshed recently. Anything that stopped happening more than a few minutes ago has already been deleted.

That means every event you can see has a recent lastTimestamp no matter what is going on. Looking at five events with nearly identical last-seen times and concluding “these all fired together” is circular. They look simultaneous because only the recently refreshed ones survive.

How I found the real picture

I stopped using the event list as evidence of timing and looked at what the events could actually tell me: rates. The one event object for this service had been first seen on a Wednesday, and by the time I looked it had a count of 440. That works out to 440 failures over about three and a half days, or roughly 5 per hour across the service. That is a rate I can trust, because a count accumulates inside one long-lived object.

Then I went and watched the thing directly, since the event history was useless for timing. I polled the readiness endpoint on each replica myself and watched the Service’s endpoint list. The results, over about 770 polls:

  • the endpoint failed about 1 time in 770
  • it never failed three times in a row
  • so no pod ever stayed unready long enough to be removed from the Service

The “all replicas fail together” story was wrong. The real behaviour was occasional, isolated, single-poll failures that the Service never even noticed. Low impact. I would rather leave the exact cause open in my notes than invent a tidy answer. The important thing is that I stopped sending myself down the wrong road.

The same trap in application logs

A month earlier I had made a close cousin of this mistake with logs. One of my services was very chatty: hundreds of log lines per second across its replicas, nearly all of it info-level noise.

That volume has a consequence. Container log rotation is by size, not by time, so asking for the last six hours returned only the last few minutes.

I had bucketed errors by hour. Every error landed in the current hour, with apparently zero errors in the previous five. It looked like a sudden burst that had just begun, and I reported a live “write storm.” In fact the earlier hours had simply been rotated away. The errors arrived in one-minute waves that tracked a batch scheduler. A fixed 60-second sample showed 13 errors across all replicas. A two-minute sample taken minutes earlier had shown about 400. Spiky at minute scale, normal in aggregate.

# wrong: a histogram over a window the logs cannot cover
kubectl logs deploy/myservice --since=6h | bucket-by-hour

# better: a fixed short window, expressed as a rate
kubectl logs deploy/myservice --since=60s --all-containers | grep -c "duplicate"
kubectl logs deploy/myservice --since=5m  --all-containers | grep -c "duplicate"

The general principle

Both of these failures share the same structure. The tool gave me a window onto the data that was narrower than I believed. I had a model in my head of “events” and “logs” as a complete record, when they were a recent sliver. Everything I concluded about timing and correlation came from the shape of the sliver.

Whenever evidence has a retention limit, the retention limit is part of the evidence. A cluster that keeps only a few minutes of events cannot answer questions about what happened an hour ago, and it will happily answer anyway by showing you whatever survived.

What I do now

  • Use count and firstTimestamp for rates, never lastTimestamp for correlation. A count accumulated over days is a rate. A last-seen time is just a statement about the retention window.
  • If I need timing, I observe it directly. Poll the endpoint, watch the endpoint list, read logs with an explicit --since-time that I know the logs still cover.
  • Check how far back the evidence actually goes before reasoning from it. One command, kubectl get events -A | wc -l, would have saved me the wrong theory.
  • Sample over fixed windows and report rates, not histograms. If retention is shorter than your bucket size, the bucketing manufactures a trend.
  • Reduce noise at the source. A service that emits hundreds of lines a second has only minutes of memory. When something real breaks, there is no history left to debug. Dropping info-level chatter is a reliability fix, not just a tidiness one.
  • Write down what you do not know. My notes now say plainly when a cause is unconfirmed. That is more useful to future me than a confident wrong answer.

The uncomfortable bit is that every individual piece of evidence I used was real. The events existed. The timestamps were accurate. The error lines were genuine. The conclusion was still wrong, because I had not asked what the evidence was a sample of. That is worth asking every time.

By Alex Rivers

I write hands-on guides to web development and programming: JavaScript and React patterns, Python scripting, CSS layout and the developer tools that tie it all together. I like explanations that start with working code and end with knowing why it works. If a post saves you an afternoon of debugging, it did its job.

Leave a Reply