Kubernetes Core Architecture: Cluster, Pod, Deployment, and Declarative Management
DevOps Learning Notes
Using kind to create a local K8s cluster, understanding Cluster, Node, Pod, and Deployment relationships from scratch, and the core mindset of K8s declarative management
Cluster Composition and Node Roles
A K8s cluster consists of two roles:
- Control Plane: the brain, responsible for decisions (scheduling, monitoring, storing state)
- Worker Node: the hands and feet, responsible for actually running containers
A typical production cluster:
|
|
Control Plane runs 3 nodes because etcd (the database storing all cluster state) needs an odd number for consensus โ if one goes down, the remaining two can still vote for a leader, and the cluster continues operating.
Brain Components
| Component | Role |
|---|---|
| API Server | Entry point for all operations. kubectl communicates with it |
| etcd | Distributed key-value database, stores the entire cluster’s state |
| Scheduler | Decides which Node a Pod runs on |
| Controller Manager | Runs various controllers (Deployment, ReplicaSet, etc.) |
Workload-Machine Daemons
| Component | Role |
|---|---|
| kubelet | Agent on each Node, ensures Pods are actually running |
| kube-proxy | Maintains network rules (iptables/ipvs), enables Service routing to Pods |
| container runtime | What actually runs containers (containerd) |
Spinning Up a Test Group Locally
kind (Kubernetes IN Docker) runs the entire K8s cluster inside a Docker container, for learning and testing.
|
|
What this command does:
|
|
kind’s special feature: one Docker container plays both Control Plane + Worker, so kubectl get nodes will only show one Node.
Connection Target Selection in kubeconfig
kubectl uses context to know which cluster to connect to. After kind create completes, it automatically sets kind-devops-lab as the active context.
|
|
If you have multiple clusters simultaneously (e.g., kind + AWS EKS), you need to use --context to specify.
Making Local Images Available to the Cluster
The container runtime inside kind (containerd) is isolated from the local Docker daemon. Images built with local docker build are not visible to kind.
|
|
|
|
kind load only transfers the image, it doesn’t start anything. Only when kubectl apply runs will kubelet use this image to create a container.
You can verify the image is in the Node with crictl:
|
|
crictl is a CLI for interacting with containerd, just like the docker command is a CLI for interacting with the Docker daemon.
Smallest Schedulable Workload Primitive
A Pod is a wrapper K8s adds on top of containers.
|
|
Containers in the same Pod share network (same IP, communicate via localhost) and storage. In most cases, it’s one Pod one container.
Why K8s Wraps Containers in Pods
K8s’s smallest management unit is Pod, not container:
- Scheduling: Scheduler places the entire Pod onto a Node
- IP: Assigned to the Pod, containers within the same Pod share it
- Lifecycle: When a Pod dies, all containers inside die together
Workload Specification Sample
|
|
|
|
From kubectl apply to Running Container
The Events section of kubectl describe pod records the complete process:
|
|
Mapped to component collaboration:
|
|
Pods Disappear Without a Controller
|
|
Two key observations:
- Deleting a Pod, nothing will recreate it for you
- Re-applying, the Pod gets a different IP
This is why you don’t use bare Pods in production โ you need a Deployment to manage them.
Kubernetes Tenant Scope Versus OS Isolation Primitives
Same name, completely different things:
- Linux Namespace (from Phase 1 content): kernel-level isolation mechanism (PID, Network, Mount…)
- K8s Namespace: logical grouping, like folders classifying resources in a cluster
|
|
ReplicaSet Driver: Autonomous Replica Guardian
Deployment solves two problems with bare Pods: they’re gone when deleted, and you can’t do zero-downtime updates.
Owner Chain: Deployment โ ReplicaSet โ Pod
|
|
You only manage the Deployment. ReplicaSet and Pods are managed automatically.
Pod Manifest Referencing the Registry
|
|
Everything under template is the spec from the earlier pod.yaml, now wrapped inside the Deployment.
Auto-Generated Naming Convention
|
|
You can see the Deployment โ ReplicaSet โ Pod hierarchy from the names alone.
Convergence Toward Declared Intent
|
|
Completely different from bare Pods โ delete one, a replacement is created immediately:
|
|
This loop runs continuously. No matter how a Pod dies โ manual deletion, crash, Node failure โ it will be replaced.
Zero-Downtime Image Changes
When updating the image version, the Deployment manages two ReplicaSets simultaneously:
|
|
maxSurge: 1, maxUnavailable: 0 means: first create the new Pod and confirm Ready, then kill the old Pod โ achieving zero downtime.
Production Workflows Use Deployments Directly
In real work, you write Deployments directly:
|
|
Deployment automatically creates ReplicaSet and Pods. No need to write a separate pod.yaml.
Desired-State Configuration Model
K8s core mindset โ you write YAML describing “the state I want”, and K8s makes it happen:
|
|
This is the same mindset as Terraform and Docker Compose, all belonging to Infrastructure as Code (IaC):
| Tool | What It Manages |
|---|---|
| Terraform | Cloud resources (EC2, RDS, VPC…) |
| Docker Compose | Local multiple containers |
| K8s YAML | Application deployment in cluster |
YAML files go into git, changes are trackable, all infrastructure is defined and managed through code.
Management Commands for the Test Group
A kind cluster is just a Docker container, manageable directly with Docker:
|
|
kind doesn’t use Docker Compose. kind creates containers itself using the Docker API.
References
- Kubernetes Documentation โ Overview โ official K8s concept overview
- Kubernetes Documentation โ Pods โ Pod design philosophy and lifecycle
- Kubernetes Documentation โ Deployments โ complete explanation of Deployment, ReplicaSet, and rolling updates
- kind โ Quick Start โ kind installation and usage guide