Kubernetes Informers are so easy... to misuse!
Kubernetes Informers report the eventual current state of an object, not every intermediate transition, so controllers must use level-driven logic rather than comparing oldObj and newObj in UpdateFunc. Each handler processes events serially and buffers pending notifications in an unbounded ring buffer, so a slow handler facing a large initial LIST (around 10^5 items at Render) can trigger an "OOMLoop" in which the Pod is OOM-killed and restarted repeatedly. Render recommends keeping handlers fast or using a workqueue, reading from the Informer cache instead of the API, filtering with WithTweakListOptions label selectors, and trimming objects with SetTransform. SetTransform carries a debugging cost, because zeroed-out fields can confuse tools and future teammates.
Related posts
- Node.js and the tale of worker threads
Zalando Engineering mediumAdeptA Node.js service using cluster mode called os.cpus().length inside a Kubernetes container, which returns the host's core count, not the pod's CPU allocation. On a 48-core node it forked 48 processes inside a 2GB pod. Each needed about 120MB, so the processes were killed under memory pressure and immediately re-forked by the exit handler, flooding a translation service with startup requests (1,000 to 20,000 rpm) and causing cancelled connections and read timeouts. The initial diagnosis of a retry feedback loop caused by process.exit() on fetch failure turned out to be wrong. The fix was to drop cluster mode and let Kubernetes handle scaling, and the incident motivated adding event-loop lag and other signals through an internal Node.js observability SDK.
- Thundering herd of circuit breakers
Zalando Engineering mediumAdeptA client's circuit breaker stayed open for hours because its half-open probes hit a service that the HPA had scaled down to three pods. The sparse probes succeeded, the breaker closed, and the withheld traffic arrived at once, queued for over 100 ms per request, timed out and re-opened the breaker. Each cycle lasted only about three seconds, too short for CPU-averaged autoscaling to notice. Zalando found the cycle by exporting OpenTelemetry traces as CSV into a bespoke uPlot visualizer that plots hundreds of traces at once. Suggested fixes are autoscaling on queue depth or concurrency, longer or heavier half-open probes, pre-scaling before the breaker closes, load shedding, and propagating cancellations.
- How the controller-runtime Cache Actually Works, and Why Your Controller Does Not Crash the API Server
Kubernetes Blog hardMasterIn controller-runtime, r.Get() and r.List() inside a reconciler read from a local in-memory cache built on client-go informers. That cache is filled by a list + watch (now a streaming list with sendInitialEvents) and kept current by the Reflector using resourceVersion, with relists only after 410 Gone. Since client-go 1.36 the delta queue is RealFIFO, which delivers every delta in global order with no deduplication; coalescing of bursts happens only in the controller's workqueue, keyed by namespace/name. The design makes reads nearly free, but it brings stale reads after writes, memory growth from cached objects and indexes, and hidden O(n) List scans, and occasionally a need for APIReader.
- How We Found 7 TiB of Memory Just Sitting Around
Render mediumAdept
Render's Kubernetes clusters have an unusually large number of namespaces, and daemonsets that listwatch them, such as Vector's kubernetes_logs source, used gigabytes of memory per node and put load on the apiserver during rollouts. Render added an opt-in config option to Vector (insert_namespace_fields) that disables namespace watching, since its config only used namespace labels to identify user pods. A missed second kubernetes_logs source initially hid part of the savings. Per-pod memory fell from nearly 4 GiB to tens of MiB, which freed about 1 TiB on the largest cluster and just over 7 TiB across the fleet.
- Our journey taking Kubernetes state metrics to the next level
Datadog Engineering mediumAdeptDatadog's Containers team made kube-state-metrics usable as a library: an upstream PR made the KSM Builder extensible so the MetricStore could be swapped out, with neutral-to-slightly-better benchmark results. Embedding KSM's informers directly in the Datadog Agent as a long-running Go core check, run on Cluster Check Runners or the Cluster Agent, removed the costly crawl of the /metrics endpoint. Large clusters had been producing millions of metrics every 15 seconds, and this change cut collection time 15x and halved memory and CPU footprint. It also required extending the Agent collector's interface to support long-lived check threads.