Kubernetes Principles, Controllers, and Resource Model
From infrastructure toolkits to application abstractions
Traditional cloud toolkits such as OpenStack focus on infrastructure-layer primitives—virtual machines, virtual networks, and virtual block storage. Kubernetes (K8s, pronounced coo-ber-net-ees, inspired by Google’s internal Borg and Omega systems) introduces higher-level application-oriented abstractions designed to compose cleanly across thousands of machines.
Its user-facing model rests on three foundational principles:
- APIs decoupled from implementation: You declare a standard resource (for example, a LoadBalancer or StorageClass), and each cloud provider or on-premises plugin implements it differently behind the same API.
- Declarative specification (Infrastructure as Code): You describe what state you want rather than writing step-by-step control flow to reach it.
- State-oriented (control-loop) execution: Background controllers continuously compare observed cluster state against your desired state and drive reality to match.
Imperative vs. declarative control
For the broader Infrastructure-as-Code and GitOps motivation behind declarative configuration and idempotency, see Declarative Configuration and Idempotency.
| Dimension | Imperative | Declarative |
|---|---|---|
| Example command | ”Add one more container instance" | "Ensure two container instances are running” |
| Sensitivity to starting state | Weak: 1 running → 2; 10 running → 11 | Idempotent: 1 running → adds 1; 10 running → removes 8 |
| User-side logic | Complex (if/else checks before acting) | Simple (declare the target count/state) |
| Orchestrator complexity | Low (executes one command and exits) | High (must continuously maintain desired state at runtime, replacing crashed containers automatically) |
How the state-oriented control loop works
- A client submits a desired configuration (Client Spec), which undergoes Defaulting to produce the stored Object Spec.
- A Controller (part of
kube-controller-managerfor core resources, or a custom Operator for user-defined resources) watches shared cluster state throughkube-apiserverusing Informers plus a periodic resync period. - During Enforcement / Reconcile, the controller inspects the real Object State in the external world, performs changes to move current state toward desired
spec, and writes back Reaction / status updates (re-queueing with backoff if a conflict error occurs).
Uniform structure of every Kubernetes resource
Every Kubernetes object shares the same YAML schema:
apiVersion+kind: Unambiguously identifies the resource schema and type (e.g.,apiVersion: v1,kind: Pod).metadata:name(and optionalnamespace)labels: Key-value pairs relevant to users and selectors (e.g.,release: stable)—they carry no built-in core system semantics.annotations: Non-identifying metadata consumed by external tools, plugins, or libraries (e.g.,k8s.v1.cni.cncf.io/networks: multus1).
spec: Desired state supplied by the user.status: Observed current state updated by Kubernetes controllers.
Common confusions
labelsvs.annotations: Use labels when Kubernetes objects (likeServiceorReplicaSet) need to select or group resources vialabelSelector; use annotations to attach descriptive or third-party configuration hints that selectors do not query.- Declarative does not mean “fire and forget once”: The reconciliation loop never stops after creation—if a container crashes hours later, controllers reconcile observed
statusback towardspec.
Retrieval
- Why is “add one container” fragile compared to “maintain three containers”, and which side carries more runtime complexity in the second model?
”Add one container” depends on starting conditions (1 becomes 2, 10 becomes 11) and breaks if a previous step ran twice. “Maintain three containers” shifts runtime complexity onto the orchestrator, whose controllers continuously detect drift or crashes and add or remove replicas to converge on 3. - In a Kubernetes YAML manifest, what is the practical difference between
spec,status,labels, andannotations?
specholds user-defined desired state;statusrecords controller-observed current state;labelsare key-value tags used by selectors to group objects;annotationscarry rich metadata for external tools without affecting label selection.
Source: Lecture 11 - Kubernetes, PDF pages 2 and 5–10 (printed slides 3 and 6–11).