Problem & context
A single KubeDB operator pod reconciles every database custom resource in a cluster. That works for a few hundred objects, but as clusters grow to thousands of database instances — each with continuous autoscaler reconciliation and recommendation work — one replica becomes the bottleneck.
Running more replicas only helps if work is split between them without duplicates, and without reshuffling everything when the replica count changes.
Architecture
- The Operator Shard Manager assigns each managed resource to an operator replica using consistent hashing with bounded loads, and records the assignment as a label on the resource.
- A ShardConfiguration object targets an API group (e.g. autoscaling.kubedb.com), so every autoscaler kind — Postgres, MSSQLServer, MongoDB, MySQL, MariaDB, Redis, Elasticsearch, Kafka and more — is sharded without per-kind configuration.
- Each replica (StatefulSet pod index 0…n) only processes resources labelled with its own index.
Engineering challenges
- Avoiding duplicate processing between replicas.
- Keeping load off the Kubernetes API server — filtering in memory after listing everything would still load the API server.
- Scaling replicas up or down without a cold start: moving every resource would discard warm caches and metrics history.
Implementation
- Made the autoscaler’s recommender pipeline shard-aware by threading a shard label selector (client.MatchingLabels) down to every List() call, so the API server itself returns only that replica’s objects.
- Enabled sharding through Helm values (operator-shard-manager.enabled, kubedb-autoscaler.replicaCount) in kubedb/installer, and added samples to kubeops/operator-shard-manager.
- Wrote the announcement blog post walking through enabling sharding, verifying shard labels and operator logs.
Technical decisions
- Consistent hashing (with bounded loads) rather than modulo hashing: scaling from 3 to 5 replicas relabels only ~40% of autoscalers while ~60% stay put, keeping caches warm and avoiding API traffic spikes.
- Server-side label filtering rather than client-side filtering, so each of n pods does ~1/n of the work in CPU, memory and network I/O.
- Targeting the API group rather than individual kinds, so existing autoscaler CRs need no changes.
My contribution
- Leveraged consistent hashing to shard KubeDB-managed workloads across multiple operator replicas, enabling parallel processing at scale.
- Implemented autoscaler sharding support and authored the public announcement.
Outcomes & impact
- The KubeDB autoscaler operator can scale horizontally — each pod manages fewer autoscalers, with zero duplicate processing.
- No changes are required to users’ existing autoscaler custom resources.