Video in progress

Why use a Deployment instead of creating a Pod directly?

A Deployment keeps the desired number of replicas, brings up a new Pod when one crashes, and rolls out a new version step by step. If a standalone Pod dies, nobody restores it.

📖 Answer

In a Deployment you describe the desired state: which image, how many replicas. Kubernetes does the rest.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: shop-api
spec:
  replicas: 3
  selector:
    matchLabels: { app: shop-api }
  template:
    metadata:
      labels: { app: shop-api }
    spec:
      containers:
        - name: app
          image: registry.example.uz/shop-api:1.4.0
          ports:
            - containerPort: 8080

There is a chain inside: Deployment → ReplicaSet → Pods. If you change the image tag, the Deployment creates a new ReplicaSet and gradually replaces the old Pods with new ones. The old ReplicaSet is kept, so going back to the previous version with kubectl rollout undo is easy.