Master Kubernetes Core Components: Pods, ReplicaSets, Deployments & StatefulSets
This article explains the fundamental principles of Kubernetes core components—including pods, their networking and storage mechanisms, the role of ReplicaSets for scaling, how Deployments enable rolling updates, and how StatefulSets manage stateful services—providing clear insights and visual diagrams for each concept.
1. Core Component Principles – Pod Fundamentals
1.1 What is a pod
Pod can be understood as a container that holds Docker containers; it encapsulates containers.
Pod is a virtualized group with its own IP address and hostname, using namespaces for resource isolation, similar to an independent sandbox.
Pod behaves like an independent host that can encapsulate one or multiple related containers, with internal containers communicating via localhost.
1.2 What are pods used for
When deploying services, pods manage a set of related services. A pod may contain a single service or a group of interrelated services, as illustrated by the diagram where multiple containers reside within a pod.
Understanding a group of related services: a request first reaches Nginx, which forwards it to a web container, which then accesses a database; the response travels back through the same chain to the user.
1.3 Implementing a web service cluster
Simply replicate multiple pod instances; Kubernetes scales by controlling the number of pods. For example, a service cluster can be created by copying the pod configuration multiple times.
1.4 Underlying network and storage of pods
Containers inside a pod have their own IP and ports. Direct IP:port communication can affect performance; to improve internal communication, Kubernetes uses a pause container.
Pod underlying mechanism
Before creating containers inside a pod, a pause container is created. The pause container provides shared network and shared storage.
All service containers share the pause container's storage, delegating data persistence to it.
The pause container also acts as the network interface for the three containers, allowing localhost communication with high performance, similar to virtual machines pinging each other.
2. ReplicaSet – Replication Controller
2.1 Basic understanding of replica controllers
Purpose: manage the number of pod replicas (service clusters) to always match the desired count, e.g., replicas = 3 creates three pods.
If a pod fails, the ReplicaSet immediately creates a new pod to maintain the set count.
2.2 Differences between ReplicaSet and ReplicationController
Both are replica controllers, but:
Same functionality as described in 2.1.
Difference: label selector capabilities. ReplicaSet supports both single and composite label selection, while ReplicationController only supports single selection.
Labels (key=value) such as app=web, release=stable allow the controller to select a group of related services. When the selector matches a pod's labels, the pod is managed by that controller.
Because ReplicaSet offers richer functionality, it is recommended over ReplicationController in newer Kubernetes versions.
3. Deployment – Deployment Object
3.1 Rolling updates
ReplicaSet keeps pod counts constant, but applications evolve. Instead of stopping services, Kubernetes performs rolling updates by creating new pods (v2) to replace old ones (v1).
3.2 Deployment model
A standalone ReplicaSet cannot perform rolling updates; Deployment objects enable this feature, usually working together with ReplicaSets.
Steps for a rolling update:
Deployment creates a new ReplicaSet.
The new ReplicaSet creates new pods.
Thus, Deployment manages ReplicaSet, which manages pods. During an update, old pods are removed while the previous ReplicaSet remains, allowing rollback if needed.
4. StatefulSet – Deploying Stateful Services
4.1 Introduction
Consider deploying MySQL (a stateful service) in containers: container lifecycles cause data loss on crash, and pod lifecycles can also lead to data loss when pods are restarted.
Therefore, Deployment is suited for stateless services, while StatefulSet addresses the challenges of stateful services in Kubernetes.
4.2 Understanding stateful vs. stateless services
Stateful services require real-time data storage and cannot rejoin the cluster seamlessly after being removed.
Stateless services do not need persistent data; removing and re‑adding a pod does not affect the overall cluster.
4.3 Deployment model
StatefulSet deployment is similar to Deployment but uses PersistentVolumeClaims (PVC) to store real-time data.
When a pod crashes, StatefulSet preserves the hostname, allowing the new pod to locate its previous data.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
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.