5 Kubernetes API and Object Model
Kubernetes API and Object Model provide a structured way to manage and interact with containerized applications in a scalable and automated infrastructure environment.
Kubernetes API and Object Model is the design foundation through which every entity in a Kubernetes cluster, from workloads to configuration to infrastructure abstractions, is represented as a structured, versioned resource accessible through a single consistent REST API, rather than through disparate ad hoc interfaces.
The API Server as the Single Entry Point
Uniform Access
All interaction with a Kubernetes cluster, whether from the kubectl command-line tool, a controller, or an external application, passes through the same API server using the same HTTP conventions, meaning any client capable of speaking REST can inspect or modify cluster state.
Resource-Oriented Design
The API is organized around resources rather than actions. Instead of exposing an endpoint that performs a specific operation, Kubernetes exposes resources that can be created, read, updated, or deleted, with the underlying controllers deciding what actions to take in response to those changes.
Anatomy of an Object
apiVersion, kind, metadata, spec, and status
Every Kubernetes object follows the same basic structure: an apiVersion and kind identifying the resource type, metadata describing identifying information such as name and labels, a spec describing the desired state, and a status describing the last observed actual state.
Spec and Status Separation
This separation is fundamental to the declarative model. Clients only ever write to spec, describing what they want, while controllers write to status, reporting what is actually happening, which prevents clients and controllers from fighting over the same fields.
API Groups and Versioning
Grouping Resources
Resources are organized into API groups, such as the core group for fundamental resources like Pods and Services, and named groups like apps or batch for higher-level workload resources like Deployments and Jobs.
Version Stability Levels
Each API version carries a stability designation: alpha versions may change or be removed without notice, beta versions are more stable but may still evolve, and stable (v1) versions are guaranteed to remain backward compatible across releases.
Labels, Selectors, and Annotations
Labels
Labels are arbitrary key-value pairs attached to objects, used to organize and select subsets of resources. They are the mechanism by which loosely coupled relationships, such as a Service selecting the Pods it should route to, are expressed.
Selectors
Selectors are queries against labels, used throughout the API by Services, ReplicaSets, and NetworkPolicies to dynamically determine which objects they apply to.
Annotations
Annotations also attach key-value metadata to objects but are intended for non-identifying information, such as build details or tooling-specific configuration, and are not used for selection.
Watch and Informers
The Watch Mechanism
Rather than requiring clients to poll for changes, the API server supports a watch mechanism that streams change events as they happen, allowing controllers to react to cluster state changes with low latency.
Informers
Client libraries build on the watch mechanism with informers, which maintain a local, continuously updated cache of resources, reducing load on the API server when many controllers need to observe the same resource type.
Extending the Object Model
Custom Resource Definitions
Custom Resource Definitions (CRDs) allow new object types to be registered with the API server, extending the object model to represent domain-specific concepts using the same conventions as built-in resources.
API Aggregation
The aggregation layer allows entirely separate API servers to be registered underneath the main API server's URL space, enabling more advanced extension scenarios beyond what CRDs alone support.
API Interaction Diagram
This uniform, resource-centric API design is what makes Kubernetes extensible: any tool that understands the conventions of the API can interoperate with the cluster without requiring special-cased integrations.
Content in this section
- 5.1 Kubernetes API and Object Model Scope
- 5.2 Kubernetes API Resource Model
- 5.3 Kubernetes API Group Model
- 5.4 Kubernetes API Version Model
- 5.5 Kubernetes Kind and Resource Model
- 5.6 Kubernetes Object Structure
- 5.7 Kubernetes Object Metadata Model
- 5.8 Kubernetes Object Naming Model
- 5.9 Kubernetes Label and Selector Model
- 5.10 Kubernetes Annotation Model
- 5.11 Kubernetes Spec and Status Model
- 5.12 Kubernetes API Request Model
- 5.13 Kubernetes API Validation Model
- 5.14 Kubernetes API Defaulting Model
- 5.15 Kubernetes API Patch Model
- 5.16 Kubernetes Server Side Apply Model
- 5.17 Kubernetes API Subresource Model
- 5.18 Kubernetes Object Lifecycle Model
- 5.19 Kubernetes Object Deletion Model
- 5.20 Kubernetes Ownership Model
- 5.21 Kubernetes List and Watch Model
- 5.22 Kubernetes API Discovery Model
- 5.23 Kubernetes Object Schema Model
- 5.24 Kubernetes Object Conversion Model
- 5.25 Kubernetes API Compatibility Model
- 5.26 Kubernetes Client Object Interaction