Sub topic 10
Slowing a Rollout with minReadySeconds
This chapter assumes you can apply a Deployment manifest, read kubectl get output, and know that a readiness probe decides whether a Pod is Ready. It also assumes you know what maxSurge and maxUnavailable do.
The problem: Ready is not the same as healthy
A readiness probe tells Kubernetes that a container can answer a request right now. It cannot tell whether the container will still be working in ten seconds. Some applications pass the probe at startup and then crash when they load a large cache, open a connection pool, or hit a bad configuration value.
Without any delay, the rollout controller counts a new Pod as available the moment it becomes Ready. It can then terminate an old Pod and move on. If the new Pod fails a few seconds later, the old Pod is already gone.
What minReadySeconds does
minReadySeconds is a field in the Deployment spec. It sets the number of seconds a new Pod must stay Ready, with none of its containers crashing, before the Pod counts as available. The default is 0.
The Pod still receives traffic as soon as it is Ready. The field only changes when the Deployment controller counts the Pod as available. The rollout does not remove another old Pod until enough new Pods are available, so every step of the rollout slows down.
The rule above is shown here as a timeline.
Example
The Deployment from this tutorial already sets minReadySeconds: 5.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 4
revisionHistoryLimit: 5
progressDeadlineSeconds: 300
minReadySeconds: 5
selector:
matchLabels:
app: web
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.26
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /
port: 80
periodSeconds: 5With maxSurge: 1 and maxUnavailable: 0, the controller adds one new Pod. It waits until that Pod has been Ready for 5 seconds. Only then does it remove one old Pod and add the next new one. Four replicas take at least 20 seconds of waiting, in addition to startup and probe time.
You can see the effect with a normal update:
kubectl set image deployment/web web=nginx:1.27
kubectl rollout status deployment/web
kubectl get pods -l app=webDuring the rollout, a new Pod can show 1/1 in the READY column while the Deployment still reports it as not yet available. Run kubectl get deployment web and compare the READY and AVAILABLE columns.
Choosing a value
- Use a value a little longer than the time your application needs to show a startup crash. For many services that is 5 to 30 seconds.
- Keep the value well below
progressDeadlineSeconds. The deadline covers the whole rollout, so a largeminReadySecondsmultiplied by many replicas can trigger a false "failed" report. - Treat the field as a safety delay, not a health check. A Pod that crashes during the wait restarts its timer, and the rollout stalls instead of replacing healthy Pods.
Common mistakes
- Setting
minReadySecondsto compensate for a missing readiness probe. Without a probe, a Pod is Ready as soon as its containers start, so the delay only measures time since startup. - Expecting the Pod to be held back from Services. Traffic starts at Ready, not at available.
- Forgetting that the field is not part of the Pod template. Changing only
minReadySecondsdoes not create a new ReplicaSet or start a rollout.
Exercise
A Deployment has 6 replicas, maxSurge 1, maxUnavailable 0, and minReadySeconds 10. A new Pod passes its readiness probe, then crashes 4 seconds later. What happens to the old Pods, and why?
Show answer
The old Pods stay in place. The new Pod was Ready for only 4 seconds, so it never counted as available. With maxUnavailable 0 the controller cannot remove an old Pod until a replacement is available, so the rollout waits. If this repeats past progressDeadlineSeconds, the Deployment is reported as failed to progress.