This document explains Kubernetes objects, their properties, types, and relationships, including how they are defined, managed, and grouped using labels and namespaces.
This document details the structure, properties, and relationships of Kubernetes objects. It covers object spec and status, labels and selectors, namespaces for resource isolation, and explains how Pods, ReplicaSets, and Deployments interact to manage application workloads in a cluster.
Kubernetes objects are persistent entities that represent the desired state of resources in a cluster, such as applications, workloads, and configurations. Each object has an identity, state, and behavior, and is defined using YAML or JSON manifests managed by the Kubernetes API server.
Every Kubernetes object consists of two main fields:
Kubernetes continuously works to match the current state to the desired state defined in the spec.
Labels are key-value pairs attached to objects for identification and organization. Multiple objects can share the same label, enabling grouping and selection. Label selectors are used to identify sets of objects, forming the core grouping mechanism in Kubernetes.
flowchart TD subgraph Namespace1[Namespace: default] A[Pod: nginx-pod]:::pod B[ReplicaSet: nginx-replicaset]:::rs C[Deployment: nginx-deployment]:::deploy A -- label: app=nginx --> B B -- label selector: app=nginx --> C end classDef pod fill:#f9f,stroke:#333,stroke-width:1px; classDef rs fill:#bbf,stroke:#333,stroke-width:1px; classDef deploy fill:#bfb,stroke:#333,stroke-width:1px;
Namespaces provide a way to isolate groups of resources within a single cluster. They are useful for multi-team environments, cost-saving, or managing multiple projects. Each object name must be unique within its namespace. Common namespaces include kube-system for system resources and default for user applications.
A Pod is the smallest deployable unit in Kubernetes, representing a process or a single instance of an application. Pods usually wrap one or more containers. Replicating Pods enables horizontal scaling of applications.
Example Pod manifest:
1apiVersion: v1
2kind: Pod
3metadata:
4 name: nginx-pod
5spec:
6 containers:
7 - name: nginx
8 image: nginx
9 ports:
10 - containerPort: 80
A ReplicaSet ensures a specified number of identical Pods are running at any time. The replicas field defines the desired count, and the ReplicaSet creates or deletes Pods to match this number. The selector field uses labels to identify which Pods are managed.
Example ReplicaSet manifest:
1apiVersion: apps/v1
2kind: ReplicaSet
3metadata:
4 name: nginx-replicaset
5spec:
6 replicas: 3
7 selector:
8 matchLabels:
9 app: nginx
10 template:
11 metadata:
12 labels:
13 app: nginx
14 spec:
15 containers:
16 - name: nginx
17 image: nginx
Deployments are higher-level objects that manage ReplicaSets and provide advanced features like rolling updates. Deployments are recommended over direct use of ReplicaSets for stateless applications. They orchestrate updates, scaling, and rollbacks.
Example Deployment manifest:
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: nginx-deployment
5spec:
6 replicas: 3
7 selector:
8 matchLabels:
9 app: nginx
10 template:
11 metadata:
12 labels:
13 app: nginx
14 spec:
15 containers:
16 - name: nginx
17 image: nginx
flowchart TD D[Deployment] --> RS[ReplicaSet] RS --> P1[Pod 1] RS --> P2[Pod 2] RS --> P3[Pod 3]
Kubernetes objects are persistent, declarative resources that define and manage the state of applications in a cluster. Understanding their properties, relationships, and management patterns is essential for effective Kubernetes usage.
(2) The control plane manages the desired and actual state of the cluster, making decisions and responding to events such as scheduling workloads and creating resources.
(3) etcd does not run user applications; it stores cluster data and configuration.
| Component | Function |
|---|---|
| A. API Server | 1. Exposes the Kubernetes API |
| B. Scheduler | 2. Assigns pods to nodes |
| C. Controller Manager | 3. Runs controller processes to maintain state |
| D. etcd | 4. Stores all cluster data |
A-1, B-2, C-3, D-4.
The kubelet is responsible for ensuring that containers described in pod specifications are running and healthy on each node.
True. The kubelet communicates with the API server to receive pod specs and ensures containers are running as desired.
(1) The kubelet is responsible for starting and managing pods on the node, so its status should be checked first.
(2) Labels are key-value pairs that help organize and group objects for selection and management.
(3) Namespaces are used for both system and user resources, not just system resources.
| Object | Function |
|---|---|
| Pod | Smallest deployable unit, runs containers |
| ReplicaSet | Ensures specified number of Pods are running |
| Deployment | Manages ReplicaSets and rolling updates |
| Namespace | Isolates groups of resources |
Pod-Smallest unit, ReplicaSet-Manages replicas, Deployment-Manages ReplicaSets, Namespace-Resource isolation.
Deployments are recommended over direct use of ReplicaSets for stateless applications.
True. Deployments provide advanced management and are preferred for stateless workloads.
(3) Selector is not a property of all objects; it is specific to certain controllers like ReplicaSet.