Skip to Content
Mengty Learns
Kubernetes

Pods, ReplicaSets, and Deployments

How Kubernetes layers Pods, ReplicaSets, and Deployments to run stateless workloads and perform zero-downtime rollouts and rollbacks.

explanationbeginnerTested with kubectl 1.35.10Updated Nov 26, 2026

TL;DR

A Pod runs one or more tightly coupled containers, a ReplicaSet keeps a desired count of identical Pods alive, and a Deployment manages ReplicaSets to give you declarative rollouts and instant rollbacks.

Why it exists

A single container process cannot heal itself if the node it runs on fails, and replacing Pods one by one by hand during a release causes downtime. Kubernetes separates the runtime unit (Pod), the replica count controller (ReplicaSet), and the release controller (Deployment) so each layer has one clear job.

Mental model

Think of the three objects as a nested ownership chain:

  1. Pod — the smallest deployable unit in Kubernetes. It gives its containers a shared network namespace (one Pod IP) and shared storage volumes. Pods are mortal: if a Pod dies, it is not restarted in place as a new object; a controller creates a replacement Pod.
  2. ReplicaSet — watches a label selector (matchLabels) and reconciles the live Pod count to match spec.replicas. If a node vanishes, the ReplicaSet controller creates new Pods on healthy nodes.
  3. Deployment — sits above ReplicaSets. When you change spec.template (for example, bumping image from 1.27 to 1.28), the Deployment creates a new ReplicaSet, shifts replicas from the old ReplicaSet to the new one according to strategy.rollingUpdate (maxSurge, maxUnavailable), and retains old ReplicaSets at 0 replicas so you can roll back.

Do it

Generate a minimal Deployment manifest locally with --dry-run=client (verified with kubectl v1.34.1):

kubectl create deployment nginx --image=nginx:1.27 --replicas=3 --dry-run=client -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:1.27
        name: nginx

Apply, roll out an image update, and roll back on a live cluster:

# not run (requires cluster)
kubectl apply -f deployment.yaml
kubectl set image deployment/nginx nginx=nginx:1.28
kubectl rollout status deployment/nginx
kubectl rollout history deployment/nginx
kubectl rollout undo deployment/nginx

Gotchas

  • Mismatched selector.matchLabels and template.metadata.labels: The API server rejects a Deployment if its selector does not match the Pod template labels. Never edit selector labels in place on a running Deployment.
  • Unhealthy Pods marked Ready immediately: Without a readinessProbe, Kubernetes considers a new Pod ready as soon as its container starts, which can send traffic to a booting app during a rollout.
  • Zero-history revisionHistoryLimit: Setting spec.revisionHistoryLimit: 0 deletes old ReplicaSets immediately, which disables kubectl rollout undo.

Production checklist

  • Run stateless workloads via Deployment (never bare Pod or standalone ReplicaSet).
  • Set readinessProbe and livenessProbe so rolling updates wait for new Pods to be ready.
  • Define resources.requests and resources.limits on every container.
  • Keep revisionHistoryLimit at a positive number (default 10) for fast rollbacks.

Check yourself

Check Yourself

1. What happens when you update the container image in a Kubernetes Deployment?

2. Which resource is directly responsible for ensuring 3 identical Pod replicas stay running?

Sources