Why this lab exists
Every time a deployment rolls out a new image in production, a reconcile loop is silently doing the work. Every time a crashed pod is replaced without waking anyone up, a reconcile loop ran. Every time you scale a deployment and pods appear within seconds, a reconcile loop noticed the mismatch between desired and actual state.
Kubernetes is, at its core, a collection of reconcile loops. The API server is a store. Controllers watch that store, compute a diff between desired and actual, and take actions to close the gap. Nothing else. The genius of the design is that this loop is so simple that it provides self-healing, rollout, scale-up, and scale-down for free.
This lab builds a container orchestrator from scratch in three stages. By the end you will understand:
- Why reconcile loops are more resilient than event-driven imperative code (level-triggered vs edge-triggered)
- How a Deployment produces a ReplicaSet which produces Pods — and why this indirection exists
- What the Kubernetes watch API actually does (channel-based event stream from a thread-safe store)
- Why WorkQueue deduplication matters: a burst of 1000 identical events should not trigger 1000 reconcile calls
- What the Fabric8 Java client does when you call
client.apps().deployments().create()
The mental shift this lab produces: an orchestrator is not a scheduler. A scheduler is 5% of an orchestrator. The remaining 95% is reconcile loops, health checks, rolling updates, and event plumbing.
What we’re building
A container orchestrator in Go, built across three progressive stages.
We build:
- A
PodandNodemodel with CPU (millicores) and memory (MB) resource accounting - A first-fit
Schedulerthat scans nodes and assigns pods to the first node with capacity - A
Reconcilerthat diffs desired vs actual state and creates or terminates pods to converge - A
DeploymentControllerwithRollingUpdatestrategy (MaxSurge, MaxUnavailable) - A
HealthCheckerthat pollsGET /healthand marks pods Failed after 3 consecutive failures - A generic
Store[T]withWatch()that streamsWatchEvent[T]on a channel - An
Informer[T]that dispatches store events toEventHandlercallbacks - A
SharedInformerFactorythat returns the same informer for the same resource type - A
WorkQueuewith key deduplication: 100 identical enqueues result in 1 dequeue
We explicitly skip (and why):
- etcd and distributed state — persistence requires a full consensus protocol
- Network namespaces and CNI — the container-runtime lab covers Linux networking primitives
- kubelet and actual container lifecycle — we model pods as Go structs, not processes
- RBAC and API server authentication — security is a separate lab category
- Resource quotas and LimitRanges — per-namespace limits layer on top of per-pod limits
Mental model
Kubernetes architecture (simplified):
User applies YAML
│
▼
API Server (stores in etcd)
│ streams watch events
▼
Controllers (Deployment, ReplicaSet, etc.)
│ reconcile: desired vs actual
▼
Scheduler (picks node for each pod)
│ writes nodeName to pod spec
▼
kubelet (on the selected node)
│ calls container runtime
▼
Container starts (via containerd/runc)
Our lab covers: API Server (Store) + Controllers + Scheduler
We skip: kubelet + container runtime (see container-runtime lab)
The reconcile loop has three invariants:
-
Level-triggered, not edge-triggered. The reconciler does not react to individual events. It computes the full diff on every tick. If it misses an event (network glitch, crash), the next tick catches up.
-
Idempotent. Running Reconcile when desired matches actual is a no-op. This makes it safe to call frequently. Kubernetes calls it every 30 seconds per resource even when nothing has changed.
-
Optimistic. The reconciler assumes actions succeeded and verifies on the next tick. If creating a pod fails, the next reconcile will try again. There is no saga or rollback.
The WorkQueue’s deduplication property is the bridge between event-driven and level-triggered: informers deliver events (edge-triggered), but the queue collapses duplicates so the controller processes each resource key at most once per reconcile batch (level-triggered semantics with low latency).
Prerequisites
- Go 1.23 or later
- Familiarity with Go goroutines, channels, and the
syncpackage - Basic understanding of what a container is (PID, filesystem, network isolation) — the container-runtime lab is a useful prior read
- Conceptual understanding of declarative vs imperative configuration (you state what you want, not how to get there)
No prior Kubernetes knowledge is assumed. We build up from first principles.
Stage-by-stage build
Stage 0 Node + Pod Model with Reconcile Loop
- Define Pod, Node, Resources with CPU (millicores) and memory (MB) accounting
- Scheduler.Schedule: first-fit scan, decrement allocatable on assignment
- Reconciler.SetDesired: declare what should exist (nil = should not exist)
- Reconciler.Reconcile: diff desired vs actual, create missing, terminate excess
- Reconciler.ControlLoop: run Reconcile every interval in a goroutine
- 8 tests: schedule fits, schedule fails, reconcile creates, reconcile terminates, idempotent, resource accounting, concurrent safe, capacity exhausted
The fundamental data model of every orchestrator is the distinction between desired state and actual state. Desired state is what you declared. Actual state is what is running. The reconciler’s only job is to make actual match desired.
The Pod type is intentionally simple in v0:
type Pod struct {
Name string
Image string
Request Resources // CPU in millicores, MemoryMB in MB
Status PodStatus // Pending, Running, Failed, Terminating
}Resources stores CPU in millicores (1000m = 1 core) and memory in MB. This matches Kubernetes’ resource model. The Fits method is the scheduling decision:
func (r Resources) Fits(available Resources) bool {
return r.CPU <= available.CPU && r.MemoryMB <= available.MemoryMB
}The Scheduler implements first-fit: scan nodes in order, schedule on the first node that can accommodate the pod’s resource request.
func (s *Scheduler) Schedule(pod *Pod) (*Node, error) {
for _, n := range s.nodes {
if pod.Request.Fits(n.Allocatable) {
if err := n.AddPod(pod); err != nil {
continue // race: another goroutine took capacity
}
pod.Status = PodRunning
return n, nil
}
}
return nil, fmt.Errorf("no node has enough capacity")
}First-fit is O(n) in the number of nodes. Kubernetes uses a more sophisticated bin-packing scheduler (the default kube-scheduler scores nodes on multiple criteria: resource utilization, pod affinity, taints/tolerations). But first-fit is correct for our purposes and makes the scheduling logic transparent.
The Reconciler holds two maps:
type Reconciler struct {
desired map[string]*Pod // what should exist
actual map[string]*Pod // what actually exists
scheduler *Scheduler
}Reconcile() is a two-phase diff:
func (r *Reconciler) Reconcile() error {
// Phase 1: create pods in desired but not in actual
for name, desired := range r.desired {
if _, exists := r.actual[name]; !exists {
node, err := r.scheduler.Schedule(desired)
// ...
r.actual[name] = desired
}
}
// Phase 2: terminate pods in actual but not in desired
for name, actual := range r.actual {
if _, stillDesired := r.desired[name]; !stillDesired {
actual.Status = PodTerminating
delete(r.actual, name)
}
}
return nil
}Notice that Reconcile does not remember what happened last time. It recomputes the full diff from scratch. This is the level-triggered property: even if a prior reconcile was interrupted halfway through, the next reconcile will pick up exactly where it should be.
ControlLoop runs Reconcile on a ticker in a goroutine:
func (r *Reconciler) ControlLoop(interval time.Duration, done chan struct{}) {
go func() {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
_ = r.Reconcile()
case <-done:
return
}
}
}()
}Errors from Reconcile are silently swallowed — this matches Kubernetes’ behaviour where transient errors (API server temporarily unavailable, etcd leader election, resource conflict) are retried on the next tick rather than crashing the controller.
What the tests check: schedule fits on node (pod status becomes Running); schedule fails when all nodes lack capacity; reconcile creates missing pod (SetDesired then Reconcile, ActualPod returns non-nil); reconcile terminates excess (SetDesired nil then Reconcile, ActualPod returns nil); reconcile is idempotent (second call produces no changes); resource accounting updates on schedule (Allocatable.CPU and Allocatable.MemoryMB both decrease by request); concurrent reconcile calls with -race produce no data races; scheduling fails once node capacity is fully exhausted.
Stage 1 Deployment Controller + Rolling Update
- Deployment holds Name, Image, Replicas, RollingUpdate strategy, per-pod Request
- ReplicaSet is the intermediate abstraction — a Deployment creates one per image version
- DeploymentController.Apply: first call creates ReplicaSet, image change triggers rolling update
- Rolling update: bring up MaxSurge new pods, then terminate MaxUnavailable old pods, repeat
- HealthChecker: poll GET /health every 10s, mark pod Failed after 3 consecutive failures
- 5 tests: deployment creates pods, rolling update replaces pods, health check marks failed, failed pod replaced, max-surge honored
v0’s Reconciler works at the pod level: you declare individual pods. Real workloads need a higher-level abstraction: declare “I want 3 replicas of api:v2” and let the system manage which specific pods exist. This is what Deployment provides.
The abstraction hierarchy is:
Deployment (what you declare: image, replicas, update strategy)
│ creates/manages
▼
ReplicaSet (one per image version: which pods should exist with this image)
│ creates/manages
▼
Pod (the actual running unit: scheduled to a node)The reason for the indirection: during a rolling update from api:v1 to api:v2, both the old ReplicaSet (shrinking) and the new ReplicaSet (growing) exist simultaneously. The Deployment controller manages both. When the update is complete, the old ReplicaSet shrinks to zero replicas but is kept (for rollback). Kubernetes keeps the last 10 ReplicaSets by default.
The rolling update algorithm in DeploymentController.rollingUpdate:
// Bring up MaxSurge new pods, then terminate MaxUnavailable old pods, repeat.
for replacedOld < len(oldPods) {
// 1. Bring up up-to MaxSurge new pods
surge := maxSurge
for surge > 0 && len(newRS.Pods) < new.Replicas {
pod := &Pod{Image: new.Image, ...}
scheduler.Schedule(pod)
newRS.Pods = append(newRS.Pods, pod)
surge--
}
// 2. Terminate up-to MaxUnavailable old pods
for toTerminate > 0 && replacedOld < len(oldPods) {
oldPods[replacedOld].Status = PodTerminating
replacedOld++
toTerminate--
}
}MaxSurge: 1, MaxUnavailable: 1 means: at any point during the update, at most 1 extra pod exists above the desired replica count, and at most 1 pod is down. With 3 replicas, the cluster goes through at most 4 pods simultaneously (3 desired + 1 surge).
HealthChecker runs in a background goroutine, calling GET /health on each registered pod’s HealthEndpoint. The HTTP client is injectable for tests (a test server returning 500 replaces real HTTP calls):
type HealthChecker struct {
failures map[string]int // consecutive failure count per pod
maxFailures int // threshold before marking Failed
httpGet func(url string) (*http.Response, error) // injectable
}
func (hc *HealthChecker) check(pod *Pod) bool {
resp, err := hc.httpGet(fmt.Sprintf("%s/health", pod.HealthEndpoint))
if err != nil { return false }
defer resp.Body.Close()
return resp.StatusCode >= 200 && resp.StatusCode < 300
}When failures[pod.Name] >= maxFailures, the pod is marked PodFailed and DeploymentController.MarkPodFailed is called. The ReplaceFailedPods method then removes the failed pod and schedules a replacement — this is the self-healing loop.
Why 3 consecutive failures, not 1? Transient HTTP errors (network hiccup, GC pause) are common. A single failure triggering replacement would be extremely noisy. Kubernetes uses successThreshold, failureThreshold, and periodSeconds to tune this. Three consecutive failures is a reasonable default for a lab.
What the tests check: applying a Deployment with 3 replicas produces a ReplicaSet with 3 pods; rolling update to a new image produces a ReplicaSet with the new image name on all pods; 3 consecutive health check failures (using an httptest.Server returning 503) mark the pod Failed; after marking a pod Failed, ReplaceFailedPods removes it and schedules a replacement; the rolling update never exceeds Replicas + MaxSurge pods simultaneously.
Stage 2 Watch API + Informers + WorkQueue
- Store[T]: thread-safe map with Add/Update/Delete/List/Get and Watch() returning a channel
- WatchEvent[T]: {Type EventType, Object T} — Added, Modified, Deleted
- Informer[T]: watches Store[T], calls EventHandler{OnAdd, OnUpdate, OnDelete}
- SharedInformerFactory: same key returns same Informer instance (cache)
- WorkQueue: bounded FIFO with deduplication — 100 enqueues of same key = 1 dequeue
- 5 tests: store watch delivers events, informer calls handler, factory caches, queue deduplicates, controller reacts to informer event
v1’s DeploymentController polls for changes using Apply calls. Production controllers do not poll — they react to events. The watch API enables this: a controller registers a watch on a Store, receives events as they happen, and enqueues affected resource keys for reconcile.
The Store[T] is generic. It holds a thread-safe map and a list of watchers:
type Store[T any] struct {
mu sync.RWMutex
items map[string]T
watchers []*watcher[T]
}
func (s *Store[T]) Watch() chan WatchEvent[T] {
w := &watcher[T]{ch: make(chan WatchEvent[T], 64)}
s.watchers = append(s.watchers, w)
return w.ch
}Every Add, Update, or Delete calls broadcast, which sends to all watcher channels. Channels are buffered (64 slots). If a watcher is slow and the buffer fills, events are dropped — same as Kubernetes informers. Dropped events do not cause correctness problems because the reconciler recomputes the full diff anyway (level-triggered).
The Informer[T] wraps a Store watch and dispatches to callbacks:
type Informer[T any] struct {
store *Store[T]
handlers []EventHandler[T]
}
func (inf *Informer[T]) Run() {
ch := inf.store.Watch()
for event := range ch {
for _, h := range inf.handlers {
switch event.Type {
case EventAdded: if h.OnAdd != nil { h.OnAdd(event.Object) }
case EventModified: if h.OnUpdate != nil { h.OnUpdate(event.Object) }
case EventDeleted: if h.OnDelete != nil { h.OnDelete(event.Object) }
}
}
}
}The SharedInformerFactory ensures that multiple controllers sharing the same process reuse the same informer for the same resource type. This prevents two controllers from each making separate list/watch calls to the API server — an important optimization at scale.
The WorkQueue is the bridge between event-driven (informers) and level-triggered (reconciler) execution:
type WorkQueue struct {
items []string
inQueue map[string]bool // deduplication set
}
func (wq *WorkQueue) Enqueue(key string) bool {
if wq.inQueue[key] {
return true // already queued: skip
}
wq.items = append(wq.items, key)
wq.inQueue[key] = true
return true
}The deduplication key is typically namespace/name (e.g., "default/my-deployment"). When a Deployment changes 100 times in rapid succession (a CI/CD pipeline updating the image continuously), the queue holds exactly one entry for that deployment. One reconcile call handles all 100 changes.
The full v2 controller wiring:
// 1. Create the store.
store := NewStore[*Deployment]()
// 2. Create the work queue.
wq := NewWorkQueue(1000)
// 3. Create an informer and register a handler that enqueues on change.
inf := NewInformer(store)
inf.AddEventHandler(EventHandler[*Deployment]{
OnAdd: func(d *Deployment) { wq.Enqueue("deployments/" + d.Name) },
OnUpdate: func(d *Deployment) { wq.Enqueue("deployments/" + d.Name) },
OnDelete: func(d *Deployment) { wq.Enqueue("deployments/" + d.Name) },
})
go inf.Run()
// 4. Worker goroutine: drain the queue and reconcile.
go func() {
for {
key, ok := wq.Dequeue()
if !ok { return }
// reconcile(key) — fetch from store, diff against actual, act
}
}()This is functionally identical to how controller-runtime (the Go library used by most Kubernetes operators) wires controllers. The difference is that production uses rate-limited queues (exponential backoff on error), priority queues (some resources reconcile before others), and distributed locking (only one controller instance reconciles a given resource at a time via leader election).
What the tests check: Add/Update/Delete on Store delivers Added/Modified/Deleted events on the watch channel within 100ms; Informer calls OnAdd, OnUpdate, OnDelete exactly once each; SharedInformerFactory returns the same pointer for the same key; WorkQueue.Len() is 1 after 100 identical Enqueue calls; adding a Deployment to a Store with an attached Informer causes a key to appear in a WorkQueue.
Run it yourself
labs/container-orchestrator ↗
Go 1.23+ - 1 Clone and build
git clone https://github.com/pushkarkumar-dev/system-design-labs cd system-design-labs/labs/container-orchestrator go build ./... - 2 Run all tests
go test ./pkg/orchestrator/ -v -race - 3 Run the demo server
go run ./cmd/server/ - 4 Run benchmarks
go test ./... -bench=. -benchmem -benchtime=3s - 5 Build the Java integration
cd java-integration mvn compile
--- PASS: TestScheduleFitsOnNode (0.00s)
--- PASS: TestScheduleFailsWhenNoResources (0.00s)
--- PASS: TestReconcileCreatesMissingPod (0.00s)
--- PASS: TestReconcileTerminatesExcess (0.00s)
--- PASS: TestReconcileIsIdempotent (0.00s)
--- PASS: TestResourceAccountingUpdatesOnSchedule (0.00s)
--- PASS: TestConcurrentReconcileSafe (0.00s)
--- PASS: TestNodeCapacityExhausted (0.00s)
--- PASS: TestDeploymentCreatesPods (0.00s)
--- PASS: TestRollingUpdateReplacesPods (0.00s)
--- PASS: TestHealthCheckMarksFailed (0.00s)
--- PASS: TestFailedPodTriggersReplacement (0.00s)
--- PASS: TestMaxSurgeLimitHonored (0.00s)
--- PASS: TestStoreWatchDeliversEvents (0.00s)
--- PASS: TestInformerCallsHandler (0.00s)
--- PASS: TestSharedFactoryReturnsSameInformer (0.00s)
--- PASS: TestWorkQueueDeduplicates (0.00s)
--- PASS: TestControllerReactsToInformerEvent (0.00s)
PASS
ok github.com/pushkarkumar-dev/system-design-labs/labs/container-orchestrator/pkg/orchestrator 0.015s Benchmarks
M2 MacBook Pro, 16GB RAM | Metric | Result | Notes |
|---|---|---|
| Scheduler.Schedule (first-fit, 100 nodes) | 2,800,000 schedules/sec | estimated — linear scan until fit found |
| Reconciler.Reconcile (10 pods, no change) | 8,500,000 reconciles/sec | estimated — map diff, no-op path |
| Store.Watch event delivery | 12,000,000 events/sec | estimated — channel send per watcher |
| WorkQueue throughput (deduplicated) | 4,500,000 items/sec | estimated — mutex + map dedup + slice append |
Stress tests
What happens when all nodes are exhausted? If Reconciler.Reconcile cannot schedule a desired pod because no node has capacity, it returns an error. The pod remains in the desired map. On the next tick of ControlLoop, it tries again. This is the self-healing property: the system keeps trying. In Kubernetes, unschedulable pods enter a Pending state with a PodUnschedulable condition. The scheduler watches for node capacity changes (a pod terminating on a node frees capacity) and retries scheduling automatically.
What happens when ControlLoop ticks while a reconcile is in progress? The Reconciler uses a mutex. The second tick’s goroutine blocks at mu.Lock() until the first reconcile completes. No reconcile calls run in parallel. In Kubernetes, this is handled differently: the WorkQueue ensures at most one reconcile per resource key runs at a time, but different resource keys can reconcile concurrently.
Rolling update with MaxSurge: 0, MaxUnavailable: 1 (recreate-style). The algorithm terminates one old pod before starting one new pod. During the update, the available replica count drops by 1. This is acceptable for stateful workloads where you cannot have two pods running with the same persistent volume. Kubernetes calls this Recreate strategy — it terminates all old pods before starting new ones.
Health check thundering herd: if 100 pods all become unhealthy at the same moment (cluster-wide network partition), the HealthChecker marks all of them Failed. ReplaceFailedPods tries to schedule 100 replacements simultaneously. If node capacity can absorb them, all 100 are replaced. If not, some replacements fail — the failed pods remain in the actual map with Failed status, and the next reconcile retries. This mirrors Kubernetes’ pod disruption budgets: PDBs limit how many pods of a deployment can be unavailable simultaneously.
WorkQueue under burst: enqueueing the same key 1,000,000 times in a tight loop with 8 goroutines. The deduplication set (inQueue map[string]bool) is protected by a mutex. Under high contention the queue serializes all enqueues — this is by design. Kubernetes’s workqueue uses atomic operations for the hot path and only locks for deduplication set updates.
What the toy misses
- etcd as the state store Kubernetes stores all cluster state in etcd — a distributed key-value store with strong consistency (Raft). Our in-memory Store has no persistence and no multi-node consensus. A control-plane restart loses all state. etcd's watch API (gRPC streaming) is what Kubernetes informers actually call; our Store.Watch() emulates it in-process.
- Node agents (kubelet) In Kubernetes, the control plane schedules pods but never starts containers. The kubelet daemon on each node watches its assigned pods (via an informer on the API server) and calls the container runtime (containerd) to start/stop containers. Our Scheduler marks pods Running immediately — no actual process is started.
- Network plugin (CNI) Kubernetes pods need IP addresses. The Container Network Interface (CNI) plugin allocates IPs, sets up iptables or eBPF rules for pod-to-pod routing, and handles load balancing via kube-proxy. Our Pod has no network identity — pods cannot actually communicate with each other.
- Pod preemption and priority When resources are scarce, Kubernetes can evict lower-priority pods to make room for higher-priority ones. This requires a priority queue scheduler and careful accounting of eviction costs. Preemption interacts with PodDisruptionBudgets and is one of the most complex parts of kube-scheduler.
- Custom Resource Definitions (CRDs) Kubernetes's extensibility comes from CRDs — users define new resource types, and custom controllers (operators) reconcile them. Our Store[T] supports this pattern generically but without schema validation, conversion webhooks, or API server integration. The operator pattern (controller + CRD) is the main way production teams extend Kubernetes.
- Garbage collection and owner references When a Deployment is deleted, its ReplicaSets and Pods should be deleted too. Kubernetes tracks owner references (each resource has an ownerReferences field pointing to its parent) and runs a garbage collector that deletes orphaned objects. Cascade delete requires traversing the ownership graph — our controller does not implement this.
Wiring it into a Java/Spring service
Wiring it into a Java/Spring service
io.fabric8:kubernetes-client:6.13.0 io.fabric8:kubernetes-client-api:6.13.0 org.springframework.boot:spring-boot-starter-web:3.3.0 labs/container-orchestrator/java-integration Clone and run: cd labs/container-orchestrator/java-integration && mvn spring-boot:run What Fabric8 does under the hood
The Fabric8 Kubernetes Java client is the production-grade equivalent of our Go orchestrator. When you call client.apps().deployments().create(deployment), Fabric8 serializes the Deployment object to JSON, sends a POST request to the Kubernetes API server, and the API server stores it in etcd. The control plane’s DeploymentController (written in Go, inside kube-controller-manager) then picks up the change via its informer and reconciles.
Our Go lab implements the same reconcile loop that runs inside kube-controller-manager — just without etcd, without the API server HTTP layer, and without kubelet.
The Fabric8 equivalent of our DeploymentController.Apply:
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
Deployment deployment = new DeploymentBuilder()
.withNewMetadata()
.withName("my-app")
.withNamespace("default")
.endMetadata()
.withNewSpec()
.withReplicas(3)
.withNewStrategy()
.withType("RollingUpdate")
.withNewRollingUpdate()
.withNewMaxSurge(1)
.withNewMaxUnavailable(1)
.endRollingUpdate()
.endStrategy()
.withNewTemplate()
.withNewSpec()
.addNewContainer()
.withName("my-app")
.withImage("my-app:v2")
.endContainer()
.endSpec()
.endTemplate()
.endSpec()
.build();
client.apps().deployments()
.inNamespace("default")
.resource(deployment)
.create();
}The Fabric8 equivalent of our Store.Watch (informer-style watch):
// Fabric8 uses SharedIndexInformer — maps directly to our SharedInformerFactory
SharedIndexInformer<Deployment> informer = client.apps().deployments()
.inNamespace("default")
.inform(new ResourceEventHandler<Deployment>() {
public void onAdd(Deployment dep) {
workQueue.add(dep.getMetadata().getName());
}
public void onUpdate(Deployment old, Deployment fresh) {
workQueue.add(fresh.getMetadata().getName());
}
public void onDelete(Deployment dep, boolean deletedFinalStateUnknown) {
workQueue.add(dep.getMetadata().getName());
}
});
informer.run();This is exactly our Informer[T].AddEventHandler + inf.Run() pattern, just with Java generics and Fabric8’s type-safe builder API.
The Fabric8 equivalent of our WorkQueue:
// controller-runtime uses workqueue.RateLimitingInterface (Go)
// In Java, Spring's ApplicationEventPublisher + a bounded queue serves the same role.
// For full operator development, use Java Operator SDK (JOSDK):
// io.javaoperatorsdk:operator-framework:4.x
// JOSDK provides rate-limited work queues, retry backoff, and leader election —
// everything our WorkQueue.deduplication achieves, plus production hardening.Spring wiring (OrchestratorAutoConfiguration):
@AutoConfiguration
@EnableConfigurationProperties(OrchestratorProperties.class)
public class OrchestratorAutoConfiguration {
@Bean
public OrchestratorClient orchestratorClient(OrchestratorProperties props) {
return new OrchestratorClient(props);
}
}Configure via application.properties:
orchestrator.namespace=default
orchestrator.kubeconfig-path= What surprised me
Where to go deeper
- Kubernetes controller patterns: the official docs explain level-triggered vs edge-triggered reconciliation with concrete examples: https://kubernetes.io/docs/concepts/architecture/controller/
- Programming Kubernetes (Hausenblas and Schimanski): the definitive book on writing Kubernetes controllers. Covers client-go, informers, workqueues, and custom controllers in depth: https://programming-kubernetes.info/
- client-go SharedIndexInformer source: the actual Go implementation of the informer pattern, including delta FIFO queue and resync period: https://github.com/kubernetes/client-go/blob/master/tools/cache/shared_informer.go
- KEDA: Kubernetes Event-Driven Autoscaling — an operator that adds HPA triggers from Kafka, Redis, Prometheus, and 60 other sources. An excellent example of the CRD + controller pattern at production scale: https://keda.sh/
- Java Operator SDK (JOSDK): the Java equivalent of controller-runtime. If you want to write a production Kubernetes operator in Java with Spring Boot, JOSDK handles the informer, WorkQueue, and reconcile loop plumbing: https://javaoperatorsdk.io/
Related labs and questions
Related labs:
container-runtime— what actually happens when the kubelet calls the container runtime to start a podservice-discovery— how pods find each other (DNS-based discovery, Kubernetes Services)load-balancer— how kube-proxy distributes traffic to pod endpointsraft— the consensus algorithm that makes etcd’s strong consistency possible
Questions to test understanding:
- Why does Kubernetes have both ReplicaSet and Deployment? What does ReplicaSet add that Pod does not? What does Deployment add that ReplicaSet does not?
- If the Reconciler’s mutex is held for the full duration of a reconcile that takes 100ms, what happens to the ControlLoop ticker that fires every 50ms? Is this a problem?
- What is the maximum number of pods that can exist simultaneously during a rolling update with
Replicas=10, MaxSurge=3, MaxUnavailable=2? - Why does the WorkQueue use a map for deduplication rather than checking if the same string already appears in the slice? (Hint: what is the time complexity of each approach?)
- Kubernetes informers implement “list and watch” — they first list all existing resources, then watch for changes. Why is the initial list necessary? What would happen if you only watched without listing?