Lesson 1.6: API Objects
In Kubernetes, API objects are the fundamental building blocks that represent the state of your cluster. They are persistent entities that describe the desired state of your applications, workloads, and resources within the cluster. Kubernetes uses these objects to manage and orchestrate containers and other resources.
API objects are defined and manipulated using the Kubernetes API, which is the primary interface for interacting with the cluster. These objects are typically created, updated, or deleted using tools like kubectl
, client libraries, or directly via API calls.
Key Characteristics of API Objects:
-
Declarative Configuration: API objects are defined declaratively using
YAML
orJSON
manifests. You specify the desired state of the object, and Kubernetes works to ensure the actual state matches the desired state. -
Persistence: API objects are stored in the Kubernetes cluster's etcd database, which is a distributed key-value store. This ensures that the state of the cluster is persistent and can be recovered if the cluster restarts.
-
Grouped by API Versions: API objects are grouped into API groups and versions (e.g., v1, apps/v1, batch/v1). This allows Kubernetes to evolve its API over time while maintaining backward compatibility.
-
Hierarchical Structure: Some API objects are hierarchical, meaning they belong to or are scoped within other objects. For example, a Pod belongs to a Namespace.
Common API Objects in Kubernetes:
- Pod
- Deployment
- Service
- Namespace
- ConfigMap
- Secret
- PersistentVolume and PersistentVolumeClaim
- Role and RoleBinding:
- Ingress
How API Objects Work:
-
Desired State: You define the desired state of your application or resource using an API object manifest (YAML/JSON).
-
API Server: The Kubernetes API server receives the manifest and validates it.
-
Controllers: Controllers (e.g., Deployment Controller, ReplicaSet Controller) watch for changes to API objects and take action to ensure the actual state matches the desired state.
-
etcd: The API server stores the object's state in etcd, ensuring persistence.
-
Scheduler and Kubelet: The scheduler assigns Pods to nodes, and the kubelet on each node ensures the Pods are running as specified.