This is a very simple project to demonstrate the capability of PodDisruptionBudget.
You will need to prepare a cluster beforehand. The cluster can be an actual k8s cluster running in the cloud, or a minikube/k3s/kind cluster. The cluster should at least have 2 nodes.
- Apply
manifests/deployment.yaml - You should have two
nginxpods running. - Use
kubectl get pod -o wideto verify if they are scheduled on the same node.- They should be.
- Wait until both of them are
1/1. - Open up another terminal, and run
watch kubectl get pod.- You should be able to see a list of all running pods.
- The list should be refreshing once every few seconds.
- Now, take note of the node (node 1 from now on) on which those two pods are scheduled.
- Do
kubectl drain {{_node 1_}}.- You may need to supply
--ignore-daemonsets --force
- You may need to supply
- Take notice of the result of
watch kubectl get podin another terminal.- Both pods should restart and become
0/1 - If you try to reach the pods either through a service or by port-forwarding, you should receive
Connection reset. - After a while, those two pods should be respawned on the other node (node 2)
- Both pods should restart and become
- Now, recover the state of node by
kubectl undrain {{_node 1_}} kubectl apply -f manifests/pdb.yaml- Do
kubectl drain {{_node 2_}}. - You should see the effect of
PodDisruptionBudgetnow.