12.1.3 Handling disruptions

View in the book. Buy the book.
12.1 Node deletion without Pod disruption budgets. All the Pods on the node will become unavailable at once.
Figure 12.1 Node deletion without Pod disruption budgets. All the Pods on the node will become unavailable at once.
kubectl create -f Chapter12/12.1_PDB/pdb.yaml
12.2 With a PDB, Kubernetes will wait for the required number of Pods in a Deployment to be available before deleting others, reducing the disruption.
Figure 12.2 With a PDB, Kubernetes will wait for the required number of Pods in a Deployment to be available before deleting others, reducing the disruption.

To try, cordon and drain every node to simulate an upgrade

for node in $(kubectl get nodes -o jsonpath='{.items[*].metadata.name}'); do
  kubectl cordon $node
  kubectl drain $node --ignore-daemonsets --delete-emptydir-data
done

Then, watch the Pods

$ watch -d kubectl get pods
NAME                         READY   STATUS              RESTARTS   AGE
timeserver-f94cc5dd9-5wgnm   0/1     ContainerCreating   0          25s
timeserver-f94cc5dd9-gjc7n   1/1     Running             0          116s
timeserver-f94cc5dd9-jg47t   1/1     Terminating         0          8m45s
timeserver-f94cc5dd9-kskkw   1/1     Running             0          8m45s

Since we specified maxUnavailable: 1 there should always be 2 out of the 3 replicas in the Running state. Note that this isn’t a hard guarantee and events can disrupt this count temporarily.