kubernetes Deployments hands-on: Pod recovery

2 min read | by Jordi Prats

When we create a deployment we set how many replicas want for that pod but what happens if we delete on of the pods?

Let's assume we have a deployment that is managing the following pods:

$ kubectl get pods
NAME                   READY   STATUS    RESTARTS   AGE
demo-997c454df-4drld   1/1     Running   4          11d
demo-997c454df-slx8k   1/1     Running   4          11d

We can delete one of the pods using kubectl delete:

$ kubectl delete pod demo-997c454df-4drld
pod "demo-997c454df-4drld" deleted

If we check the deployment, the deployment controller will notice the missing pod (notice the READY column)

$ kubectl get deploy demo
pod "demo-997c454df-slx8k" deleted
NAME   READY   UP-TO-DATE   AVAILABLE   AGE
demo   1/2     2            1           11d

After a while it will spawn a new pod so that the number of replicas reaches the desired state:

$ kubectl get pods
NAME                   READY   STATUS              RESTARTS   AGE
demo-997c454df-7qflv   0/1     ContainerCreating   0          9s
demo-997c454df-slx8k   1/1     Running             4          11d

Once the new pod is ready we will be able to see that the deployment is back to 2/2:

$ kubectl get pods
NAME                   READY   STATUS    RESTARTS   AGE
demo-997c454df-6t4bg   1/1     Running   0          72s
demo-997c454df-shm8b   1/1     Running   0          39s
$ kubectl get deploy demo
NAME   READY   UP-TO-DATE   AVAILABLE   AGE
demo   2/2     2            2           11d

Posted on 23/02/2021