Understanding Kubernetes Pods, ReplicaSets, Deployments, and StatefulSets
This article explains Kubernetes core concepts—including pods as container groups, how ReplicaSets maintain desired replica counts, Deployment's rolling update mechanism, and StatefulSet's approach to managing stateful services with persistent storage—providing a comprehensive guide for cloud‑native deployments.
1. Core Component Principle — Pod Fundamentals
1.1 What is a pod
Pod can be seen as a container that holds Docker containers, essentially a container for containers.
Pod is a virtualized group with its own IP address and hostname, using namespaces for isolation, like an independent sandbox.
Pod acts like an independent host that can encapsulate one or multiple related containers, with inter‑container communication via localhost.
1.2 What are pods used for
Typically, a pod manages a set of related services; the diagram shows multiple containers (C) inside a pod.
How to understand a group of related services? A request goes to Nginx, which forwards to a web container, which accesses a database, and the response returns to the user; this chain defines related services.
1.3 Implementing a web service cluster
Simply replicate multiple pod copies; scaling up or down is done by controlling pod count.
1.4 Underlying pod network and storage
Pods have their own IP and ports; using IP:port for inter‑container communication incurs overhead. To improve performance, Kubernetes uses a pause container that shares network and storage.
Before creating containers, a pause container is created to share network and storage.
All service containers share the pause storage, delegating data storage to pause.
The pause container acts as the network interface, allowing localhost communication with high performance.
2. ReplicaSet Controller
2.1 Basic understanding
Manages the number of pod replicas to match the desired count (e.g., replicas = 3).
If a pod fails, the ReplicaSet immediately creates a new one to maintain the count.
2.2 Difference between ReplicaSet and ReplicationController
Both control replicas, but their label selector capabilities differ: ReplicaSet supports both single and composite selectors, while ReplicationController only supports single selectors.
Labels (key=value) allow the controller to identify and manage the correct pods.
3. Deployment Object
3.1 Rolling updates
Deployments enable rolling updates by creating a new pod version (v2) to replace the old one (v1) without downtime.
3.2 Deployment model
Deployment works with a ReplicaSet; the steps for a rolling update are:
Deployment creates a new ReplicaSet.
The new ReplicaSet creates new pods.
During update, old pods are removed while the old ReplicaSet remains, allowing rollback.
4. StatefulSet for Stateful Services
4.1 Motivation
Containers are transient; data can be lost if a pod restarts. Deployments are suited for stateless services, while StatefulSet addresses stateful workloads by preserving hostnames and using PersistentVolumeClaims.
4.2 Understanding stateful vs stateless services
Stateful services require real‑time data storage and cannot rejoin the cluster seamlessly after removal.
Stateless services have no persistent data and can be removed and re‑added without impact.
4.3 Deployment model
StatefulSet uses PVCs to store data; when a pod is recreated, the same hostname ensures it can locate its previous data.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
