Ordered startup
- Docker & Kubernetes course
- Advanced
- Lesson 17/70
- 4 min
Learn ordered Pod startup and shutdown.
Ordered start
With the default podManagementPolicy: OrderedReady, pods are created in order: db-1 doesn't start until db-0 is Ready. Scaling down happens in reverse (highest ordinal first). If there's no dependency between replicas, Parallel starts them all at once:
$ kubectl get pods -l app=db -w
db-0 0/1 ContainerCreating 0 2s
db-0 1/1 Running 0 9s
db-1 0/1 Pending 0 0s
db-1 1/1 Running 0 8s
db-2 0/1 Pending 0 0sPartitioned updates
A StatefulSet update also proceeds in reverse, one by one. partition updates only pods with an ordinal greater than or equal to the partition value; it's used to try the new version on one replica first (canary):
spec:
updateStrategy:
type: RollingUpdate
rollingUpdate:
partition: 2 # only db-2 is updated
kubectl patch sts db -p '{"spec":{"updateStrategy":{"rollingUpdate":{"partition":0}}}}' # update them allPractice A canary update
Write a StatefulSet's updateStrategy section (starting with updateStrategy:): type: RollingUpdate, rollingUpdate.partition: 2. Then, on a separate line, write the command watching the pods of the db StatefulSet live (-l app=db -w).
Starter code
# buraya yazSample solution
updateStrategy:
type: RollingUpdate
rollingUpdate:
partition: 2
kubectl get pods -l app=db -wExpected output
statefulset.apps/db configured NAME READY STATUS RESTARTS AGE db-2 1/1 Terminating 0 2h db-2 0/1 Pending 0 0s db-2 1/1 Running 0 9s
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Under the OrderedReady policy, what happens if db-0 never passes its readiness check?
- db-0 is deleted
- db-1 becomes the primary
- db-1 and db-2 are never created Correct answer
- All start at once
Explanation: The next pod waits for the previous one to be Ready.
2 Start the pods at the same time.
spec:
podManagementPolicy: ____
spec:
podManagementPolicy: Parallel
Explanation: Parallel doesn't wait for order.
3 Match.
| Term | Meaning |
|---|---|
OrderedReady |
In order, waiting for ready |
Parallel |
At the same time |
partition: 2 |
Only db-2 and above |
scale-down |
Starts from the highest ordinal |