← Back to Home
☸️

Pods & Deployments

From a single Pod to a self-healing, scalable Deployment.

⏱11 min readπŸ“šDevOps Fundamentals

You almost never create a bare Pod in production. Instead you create a Deployment, which manages a set of identical Pods for you β€” keeping the right number running, replacing failed ones, and rolling out new versions safely.


🎯 Learning Objectives

By the end of this lesson you will:


A Pod Manifest

Kubernetes objects are described in YAML. Here’s the simplest Pod:

yaml
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
containers:
  - name: nginx
    image: nginx:1.27
    ports:
      - containerPort: 80

Apply it with kubectl apply -f pod.yaml. But there’s a problem: if this Pod’s node dies, the Pod is gone forever. Nothing recreates it.

⚠ Don't run bare Pods in production

A standalone Pod has no self-healing. If it dies, it stays dead. Always use a controller like a Deployment, which recreates Pods to maintain your desired count.


The Deployment

A Deployment wraps your Pods and guarantees a desired number of replicas:

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3                 # keep 3 Pods running at all times
selector:
  matchLabels:
    app: web
template:                   # the Pod blueprint
  metadata:
    labels:
      app: web
  spec:
    containers:
      - name: nginx
        image: nginx:1.27
        ports:
          - containerPort: 80

Apply it and Kubernetes creates three Pods. Kill one, and a replacement appears within seconds.

bash β€” 80Γ—24
student@devops:~$kubectl apply -f deployment.yaml && kubectl get pods

Scaling

Change the replica count anytime β€” declaratively or with a quick command:

bash
kubectl scale deployment web --replicas=5   # scale up
kubectl get pods                            # now 5 pods
kubectl scale deployment web --replicas=2   # scale down

πŸ’‘ Prefer editing the YAML

kubectl scale is handy for a quick change, but in real GitOps workflows you edit the replicas value in the manifest and commit it. The manifest in Git stays the single source of truth.


Rolling Updates & Rollbacks

When you change the image version, the Deployment rolls it out gradually β€” replacing Pods a few at a time so the app never goes fully down:

bash
kubectl set image deployment/web nginx=nginx:1.28   # trigger rollout
kubectl rollout status deployment/web               # watch it
kubectl rollout undo deployment/web                 # roll back if broken
bash β€” 80Γ—24
student@devops:~$kubectl rollout status deployment/web

If the new version is broken, kubectl rollout undo instantly returns to the previous working version.


πŸ§ͺ Hands-on Lab

πŸ“

Deploy, Scale, and Self-Heal

  1. Create a Deployment of nginx with 3 replicas
  2. Delete one Pod and watch Kubernetes recreate it
  3. Scale to 5 replicas, then update the image and roll it out

🧠 Knowledge Check

Knowledge Check

Why is a Deployment preferred over creating a bare Pod?

Knowledge Check

A new version you rolled out is broken. What's the fastest safe recovery?


πŸ’Ό Interview Preparation

Interview Q&A

How does Kubernetes achieve zero-downtime deployments?


Summary

You can now run apps with Pods, use Deployments for replicas and self-healing, scale on demand, and roll out or roll back versions safely. But how does traffic reach these ever-changing Pods? That’s the job of Services β€” up next.

Up Next

Services & Networking

You've mastered this lesson. Continue your journey to becoming a DevOps Engineer.

Start Next Lesson→