Thuta Learning
IntermediateDevOpsintermediate

Deployments

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand Deployments without any of the intimidation
  • Get comfortable running kubectl commands and YAML yourself
  • Apply this concept right away in a real project

Take a moment to think about this

A Deployment manages Pods indirectly, through a 'ReplicaSet' — you tell it 'I always want 3 pods running from this image' as the desired state, and the Deployment keeps that state maintained at all times. If one Pod crashes, the Deployment immediately creates a new one to fill in (so you're back to 3 out of 3). Updating a Deployment (say, to a new image version) also triggers an automatic rolling update (covered in a later chapter).

Let's connect this to a real scenario

Writing `replicas: 3` in a Deployment YAML keeps 3 pods running at all times. If you manually delete one pod with `kubectl delete pod`, you'll see the Deployment immediately create a replacement — a hands-on demo that proves the Deployment's self-healing power for yourself.

Let's look at it together

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: web
          image: nginx:latest
          ports:
            - containerPort: 80
You should see
$ kubectl apply -f deployment.yaml
deployment.apps/web-deployment created

$ kubectl get pods
NAME                              READY   STATUS    RESTARTS   AGE
web-deployment-7d9f8c6b5-abc12    1/1     Running   0          5s
web-deployment-7d9f8c6b5-def34    1/1     Running   0          5s
web-deployment-7d9f8c6b5-ghi56    1/1     Running   0          5s

5-minute try-it

Apply the Deployment above and watch 3 pods running — then delete one with `kubectl delete pod <name>` and confirm it reappears on its own (self-healing).

A quick word of caution

Deleting a Deployment (`kubectl delete deployment`) takes down all the pods it controls too — if you only want to delete a single pod, target the pod directly (not the Deployment).

Easy traps

  • Writing a Deployment's metadata.labels and selector.matchLabels so they don't match — they need to match for the Deployment to know which pods are its own
  • Setting the replicas count without matching it to actual production traffic (too few or too many)

Now try it yourself

Apply the Deployment above and watch 3 pods running — then delete one with `kubectl delete pod <name>` and confirm it reappears on its own (self-healing).

You'll know it worked when: $ kubectl apply -f deployment.yaml deployment.apps/web-deployment created $ kubectl get pods NAME READY STATUS RESTARTS AGE web-deployment-7d9f8c6b5-abc12 1/1 Running 0 5s web-deployment-7d9f8c6b5-def34 1/1 Running 0 5s web-deployment-7d9f8c6b5-ghi56 1/1 Running 0 5s