>_ IzzyLab

Hands-on task

This task is step 4 of the course “Kubernetes: first steps”

Deployment: a pod that comes back

easy~7 min

Nobody restarts a pod started with kubectl run: delete it and it's gone. That's why applications are run through a Deployment — it makes sure its pods keep running.

Create a Deployment shop from the nginx:1.27-alpine image and wait until its pod is up. Then see how it heals itself: delete that pod and make sure the Deployment brings up a new one in its place.

What you'll practise:
  • kubernetes
  • deployment
  • kubectl create deployment
  • self-healing

Topic breakdown

A pod on its own is "mortal": if it's deleted or its node breaks, it's gone for good. That's why applications are almost never run as bare pods — they're run through a Deployment.

A Deployment is a description: "I want this many identical pods from this image running". Kubernetes constantly compares the desired state with what actually exists: a pod disappears — it creates a new one. The Deployment creates pods through an intermediate object, a ReplicaSet, which is why their names look like <deployment>-<suffix>-<suffix>.

Example — a Deployment api from the busybox:1.36 image:

kubectl create deployment api --image=busybox:1.36 -- sleep 3600
kubectl get deployments      # READY 1/1 — how many pods are ready out of how many are needed
kubectl get pods             # pod api-…
kubectl delete deployment api   # delete the Deployment along with its pods

In a Deployment's READY column, the left number is how many pods are ready, the right one is how many there should be.

What's checked

  1. Deployment shop from the nginx:1.27-alpine image
  2. The pod of Deployment shop is running
  3. The Deployment replaced the deleted pod with a new one

What it looks like