Object in Kubernetes
-
A Kubernetes object is a “record of intent”—once you create the object, the Kubernetes system will constantly work to ensure that object exists. By creating an object, you’re effectively telling the Kubernetes system what you want your cluster’s workload to look like; this is your cluster’s desired state.
-
To work with Kubernetes objects—whether to create, modify, or delete them—you’ll need to use the Kubernetes API.
-
Almost every Kubernetes object includes two nested object fields that govern the object’s configuration: the object
specand the objectstatus. For objects that have aspec, you have to set this when you create the object, providing a description of the characteristics you want the resource to have: its desired state. -
The
statusdescribes the current state of the object, supplied and updated by the Kubernetes system and its components.
Describe a object
- When you create an object in Kubernetes, you must provide the object spec that describes its desired state, as well as some basic information about the object (such as a name).
- When you use the Kubernetes API to create the object (either directly or via
kubectl), that API request must include that information as JSON in the request body. Most often, you provide the information tokubectlin a .yaml file.kubectlconverts the information to JSON when making the API request
Object Names and IDs
Each object in your cluster has a Name that is unique for that type of resource. Every Kubernetes object also has a UID that is unique across your whole cluster.
Labels and Selectors
Labels are key/value pairs that are attached to Object in Kubernetes such as Pods
Namespaces
In Kubernetes, namespaces provides a mechanism for isolating groups of resources within a single cluster.
For clusters with a few to tens of users, you should not need to create or think about namespaces at all
Initial namespaces
Kubernetes Object Management
| Management technique | Operates on | Recommended environment | Supported writers | Learning curve |
|---|---|---|---|---|
| Imperative commands | Live objects | Development projects | 1+ | Lowest |
| Imperative object configuration | Individual files | Production projects | 1 | Moderate |
| Declarative object configuration | Directories of files | Production projects | 1+ | Highest |