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:

  1. 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.
  2. Declarative specification (Infrastructure as Code): You describe what state you want rather than writing step-by-step control flow to reach it.
  3. 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.

DimensionImperativeDeclarative
Example command”Add one more container instance""Ensure two container instances are running”
Sensitivity to starting stateWeak: 1 running → 2; 10 running → 11Idempotent: 1 running → adds 1; 10 running → removes 8
User-side logicComplex (if/else checks before acting)Simple (declare the target count/state)
Orchestrator complexityLow (executes one command and exits)High (must continuously maintain desired state at runtime, replacing crashed containers automatically)

How the state-oriented control loop works

  1. A client submits a desired configuration (Client Spec), which undergoes Defaulting to produce the stored Object Spec.
  2. A Controller (part of kube-controller-manager for core resources, or a custom Operator for user-defined resources) watches shared cluster state through kube-apiserver using Informers plus a periodic resync period.
  3. 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 optional namespace)
    • 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

  • labels vs. annotations: Use labels when Kubernetes objects (like Service or ReplicaSet) need to select or group resources via labelSelector; 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 status back toward spec.

Retrieval

  1. 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.
  2. In a Kubernetes YAML manifest, what is the practical difference between spec, status, labels, and annotations?
    spec holds user-defined desired state; status records controller-observed current state; labels are key-value tags used by selectors to group objects; annotations carry 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).