Managing Kubernetes cluster stability is crucial as infrastructure grows, and handling large List requests can impact cluster stability. The Kubernetes community has introduced streaming encoding for List responses to address the issue of unnecessary memory consumption with large resources. Current API response encoders hold the complete response data as a single buffer, preventing incremental memory release during transmission. This approach becomes inefficient at large scale, leading to high and prolonged memory consumption in the kube-apiserver process. The encoding/json package and Protocol Buffers have limitations in handling large datasets, highlighting the need for streaming-based approaches. The new streaming encoder processes and transmits each item individually, allowing memory to be freed progressively as frames or chunks are transmitted. This approach reduces the memory footprint required by the API server and keeps memory consumption predictable and manageable. The streaming encoder is designed to be backward compatible, guaranteeing byte-for-byte consistency with the original encoder, and supports all Kubernetes List types without requiring client-side modifications. The introduction of streaming encoding has resulted in significant performance gains, including reduced memory consumption, improved scalability, and increased stability. Benchmark results have shown a 20x improvement in memory usage, reducing it from 70-80GB to 3GB, demonstrating the effectiveness of the new streaming encoding mechanism.
kubernetes.io
kubernetes.io
