The file ~/plains-kh28cp/api.yaml describes market-api with 3 replicas of nginx:1.27 (container web) and the default strategy. Apply it first:
sh
cat ~/plains-kh28cp/api.yaml
kubectl apply -f ~/plains-kh28cp/api.yaml
kubectl get deploy market-api -n plains-kh28cpSwitch to Recreate
Edit the file and add a strategy block under spec:
yaml
spec:
replicas: 3
strategy:
type: Recreatesh
vim ~/plains-kh28cp/api.yaml
kubectl apply -f ~/plains-kh28cp/api.yaml
kubectl get deploy market-api -n plains-kh28cp -o jsonpath='{.spec.strategy}'Roll an image through it
sh
kubectl set image deploy/market-api web=nginx:1.26 -n plains-kh28cp
kubectl get pods -n plains-kh28cp -l app=market-apiRun get pods immediately after set image. All three old Pods are Terminating at the same time and the new ones are ContainerCreating. For that moment nothing serves. That is Recreate.
text
t0 1.27 ■ ■ ■
t1 1.27 ✕ ✕ ✕ 1.26 □ □ □ ← nothing Running
t2 1.26 ■ ■ ■Back to rolling, with no gap
Change the strategy block:
yaml
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1sh
vim ~/plains-kh28cp/api.yaml
kubectl apply -f ~/plains-kh28cp/api.yaml
kubectl get deploy market-api -n plains-kh28cp -o jsonpath='{.spec.strategy.rollingUpdate}'With maxUnavailable: 0 a new Pod must be Ready before an old one is removed; maxSurge: 1 lets exactly one extra Pod exist while that happens.