DEV Community

BytePatterns
BytePatterns

Posted on Originally published at bytepatterns.com

Kubernetes Pods, ReplicaSets & Deployments Explained

If you are preparing for KCNA, CKA, or CKAD—or just trying to keep Kubernetes workload abstractions straight in production—understanding the hierarchy between Pods, ReplicaSets, and Deployments is essential.

Here is the clean mental model for how they work together.


1. The Pod: The Smallest Deployable Unit

A Pod is not a container—it is a shared execution environment around one or more containers.

All containers inside the same Pod share:

  • Network namespace: One IP address per Pod; containers inside it talk to each other over localhost on different ports.
  • Storage volumes: Mounted directories can be shared across containers in the same Pod (e.g., an app container writing logs and a sidecar shipping them).
  • Lifecycle: Pods are ephemeral. If a node dies or a Pod is evicted, Kubernetes does not "heal" that exact Pod—a higher-level controller creates a replacement Pod with a new name and a new IP.

Because Pods are ephemeral, you almost never create standalone Pods in production.


2. The ReplicaSet: Keeping N Copies Alive

A ReplicaSet watches the cluster via a label selector and reconciles reality with your desired count:

  • Too few matching Pods? The ReplicaSet creates new Pods from its template.
  • Too many matching Pods? It terminates the extras.

If a node fails and drops your count from 3 to 2, the ReplicaSet controller schedules a replacement Pod automatically.

Why don't we deploy ReplicaSets directly?

Because a ReplicaSet only maintains a count—it has no built-in mechanism for zero-downtime rolling updates or rollbacks when your container image changes.


3. The Deployment: Declarative Rollouts & Rollbacks

A Deployment sits one level above ReplicaSets and manages revisions over time.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
spec:
  replicas: 3
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: registry.example.com/api:1.4.2
          ports:
            - containerPort: 8000
Enter fullscreen mode Exit fullscreen mode

When you update image from 1.4.2 to 1.5.0:

  1. The Deployment creates a new ReplicaSet for 1.5.0.
  2. It gradually scales the new ReplicaSet up while scaling the old ReplicaSet down (respecting maxSurge and maxUnavailable).
  3. If something breaks, kubectl rollout undo deployment/api scales the previous ReplicaSet back up without rebuilding anything.

Quick Exam & Interview Recap

  • How do containers in the same Pod communicate? Over localhost (they share the Pod network namespace).
  • What actually creates and replaces Pods during a node failure? The ReplicaSet (owned by the Deployment).
  • Why use a Deployment instead of a bare ReplicaSet? Rolling updates, revision history, and instant rollbacks.

Want to go deeper? Read the full interactive lesson on Pods, ReplicaSets & Deployments or test yourself with our free 60-question KCNA practice exam (no signup required).

Top comments (0)