Deployments and ReplicaSets

Kubernetes · lesson 5 of 32 · 3 min read

Know how a Deployment keeps N healthy copies of your app alive and what the ReplicaSet underneath is for.

Open this lesson in the learning hub

Key points

  • A Deployment owns ReplicaSets, and a ReplicaSet owns pods. You edit the Deployment and never touch the rest.
  • replicas: 3 means three pods, always. Kill one and a replacement is scheduled within seconds.
  • Change anything in the pod template and the Deployment creates a new ReplicaSet, then shifts pods across to it.
  • The selector must match the template labels, and it is immutable once created.
  • kubectl scale is fine for an emergency, but the real replica count belongs in YAML in git.

Example

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: app
          image: ghcr.io/acme/web:1.4.2
          ports:
            - containerPort: 8080

You manage Deployments, Deployments manage ReplicaSets, ReplicaSets manage pods.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Kubernetes course, and every lesson in it is listed on the Kubernetes contents page.