Most content in this document is based on "Kubernetes In Action, Second Edition" by Marko Lukša and Kevin Conner.
Chapter 4 dives into the foundational structure of the Kubernetes API and its declarative object model. Rather than manipulating infrastructure directly, users and system components interact exclusively through the Kubernetes API by creating, reading, updating, and deleting (CRUD) JSON/YAML objects. This chapter deconstructs the anatomy of these objects—specifically focusing on the Node and Event objects as examples—to explain how Kubernetes represents the cluster’s state. Understanding this structure is essential for debugging and writing manifests, as every object shares a common structural philosophy built around desired state (spec) versus actual state (status).
The Kubernetes API is a RESTful API where state is represented by resources.
/api/v1/pods), while an object is a distinct instance of a resource (e.g., a specific Pod).apiVersion, kind).name, namespace, labels, annotations).graph TD
User[User/Admin] -->|Writes to| Spec[Spec: Desired State]
Controller[Kubernetes Controller] -->|Reads| Spec
Controller -->|Modifies| Infrastructure[Cluster Infrastructure]
Controller -->|Writes to| Status[Status: Actual State]
User -->|Reads from| Status
The chapter uses the Node object to illustrate these concepts. Nodes are typically created automatically by the Kubelet daemon running on the worker machine, not by the user.
Conditions are orthogonal boolean flags used across many Kubernetes objects. For a Node, these include:
MemoryPressureDiskPressurePIDPressureReady (The most critical condition; if True, the node can accept workloads).# Example Node Status Conditions Snippet
status:
conditions:
- type: MemoryPressure
status: "False"
- type: Ready
status: "True"
reason: KubeletReady
message: kubelet is posting ready status
The chapter emphasizes using kubectl explain to explore the API schema without leaving the terminal.
# Explore the schema of a Node's spec field
kubectl explain node.spec
Events are a unique type of Kubernetes object. They are not desired states; instead, they are historical records of what controllers have done or state changes that have occurred.
Normal or Warning.kubectl get events --watch (Streams events in real-time).kubectl describe <object> (Appends recent events related to that specific object at the bottom of the output).Spec (desired state), compares it to the actual infrastructure, updates the infrastructure to match the Spec, and then writes the result to the Status.Chapter 4 establishes the language of Kubernetes. By understanding the division between spec and status, users can properly interact with the declarative system. The chapter provides the necessary tools (kubectl explain, kubectl describe, and event monitoring) to allow developers to independently navigate and troubleshoot the API without needing to constantly reference external documentation.