While doing the rollback demo(12:30) i could see the kubernetes has stopped one pod which was already working and trying to create three new pods. Why is that happening?. On rolling update it should bring down one and bring up one simulataneously right?. Please help me to understand
This is about the rolling update strategy. For the deployment in the demo, it uses the default strategy, because no strategy is explicitly specified in the deployment YAML This strategy is
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
For 6 replicas, this effectively means:
-
maxSurge ≈ 2 pods
- Kubernetes is allowed to create up to 2 extra pods above the desired replica count
-
maxUnavailable ≈ 1 pod
- Kubernetes must keep at least 5 pods available at all times
(Exact rounding details aside, this is the behavior that matters.)
You end up with:
- Old ReplicaSet: 5 running pods
-
New ReplicaSet: 3 pods in
ImagePullBackOff - Total pods: 8
This happens because:
- The Deployment wants 6 available pods
- Only the old pods are available
- It can only afford to make 1 old pod unavailable
- It can temporarily run up to 2 extra pods (surge)
It is currently trying to replace one, and is surging another 2. If the image was not an incorrect image, the surge pods would become stable and it would start terminating more pods in the old replicaset.