Kubernetes Deep Dive
Kubernetes is a sophisticated distributed system that demonstrates the core principles of modern container orchestration at scale. The platform implements fundamental distributed-systems concepts โ coordination, consistency, fault tolerance โ through a carefully designed architecture that separates control logic from execution.
When you run kubectl apply -f deployment.yaml, you trigger a coordinated sequence across multiple distributed components โ each implementing specific distributed-systems patterns.
Two Planes
Kubernetes splits cleanly into a control plane (decision-making) and a data plane (execution).
This split enables horizontal scaling, fault tolerance, and clear separation of concerns โ the same architectural principles youโd use for any large distributed system.
Control Plane Components
What etcdโs Raft commit actually means
A write commits only after a majority of etcd members accept it. Three members tolerate one failure; five tolerate two. After the commit, a later read through the API server has to observe that write. Linearizability is stricter: the write takes effect at a single point between its start and its completion, so two controllers cannot both conclude they created the same object.
Lose the majority and etcd refuses further writes. Reads of the last committed state can continue, so you can still inspect the cluster. Containers that are already running stay running, because the kubelet does not need a new commit to leave them up. You cannot schedule, scale, or change a manifest until a majority is back.
The scheduler and the controller manager use that same store as a lease, not as a second consensus algorithm. Several copies may be up. The copy that holds the lease object does the work and renews it. If renewal stops, another copy takes the lease. Split brain would mean two schedulers binding the same pod; the lease is what prevents that.
Data Plane Components
The Reconciliation Loop
The pattern that makes Kubernetes work: declare desired state, the system continuously moves actual state toward it.
1. User declares desired state (Deployment YAML).
2. Controller watches the API for changes.
3. Controller compares desired vs. actual state.
4. Controller takes action to reduce the difference.
5. Loop forever.
Scheduling
When a Pod is created, the scheduler picks a node. The decision involves:
Filter, then score, then bind
Those placement factors run as two phases, then a bind.
- Filter (predicates). Drop every node that cannot run the pod. NodeResourcesFit rejects a node whose free CPU or memory is short of the podโs requests. A missed node selector, a taint the pod does not tolerate, and a node marked unschedulable fail here too. A node that fails a predicate is never scored.
- Score (priorities). Each survivor accumulates points. Preferred affinity, topology spread, and a preference for nodes with more free resources are scoring plugins. The highest total wins.
- Bind. The scheduler writes the chosen node name through the API server into etcd. The kubelet watching that node observes the binding and starts containers. Until the bind is stored, the pod is still unscheduled.
Only the lease holder runs this loop. A standby does not also bind pods. A custom scheduler replaces plugins inside the two phases; it does not insert a step between filter and bind.
Workload Resources
A few of the most-used resource types:
Service and Networking
Pods are ephemeral and have changing IPs. Services provide stable endpoints:
Configuration and Secrets
For production, integrate with a real secret manager (AWS Secrets Manager, Vault) via External Secrets Operator. Native Secrets are not enough on their own.
Storage
Operators and CRDs
Custom Resource Definitions (CRDs) let you extend the Kubernetes API. Operators package up CRDs with controllers โ exposing higher-level abstractions specific to your domain.
# A custom resource managed by an operator
apiVersion: postgres.example.com/v1
kind: PostgresCluster
metadata:
name: my-db
spec:
replicas: 3
storage: 100Gi
version: "15"
The operator watches PostgresCluster resources and reconciles them โ provisioning Postgres clusters, handling failover, managing backups. The user thinks at the level of โI want a Postgres clusterโ rather than โI want StatefulSets, PVCs, ConfigMapsโฆโ. Operators are how complex stateful systems get well-managed in K8s.
Multi-Tenancy in Kubernetes
For multi-tenant SaaS, K8s supports multiple isolation strategies:
What Makes Kubernetes Hard
The flip side: when you do master it, you have a portable, declarative, self-healing, automation-friendly platform that the entire cloud-native ecosystem builds on.
Recap
- Kubernetes splits into control plane (etcd, API server, scheduler, controllers) and data plane (kubelet, kube-proxy, runtime).
- The reconciliation loop pattern: declare desired state, controllers continuously move actual state toward it.
- Scheduling considers resources, affinity, taints/tolerations, topology.
- Core resources: Pod, Deployment (stateless), StatefulSet (stateful), DaemonSet, Job/CronJob.
- Services and Ingress provide stable endpoints and routing.
- Configuration via ConfigMaps and Secrets; Operators + CRDs extend the API for domain-specific abstractions.
- Multi-tenancy strategies range from namespace-per-tenant to cluster-per-tenant.
- The learning curve is steep โ but the operational payoff at scale is substantial.