All technological notes.
When pod template gets updated, ds controller automatically deletes the old Pods and creates the new pods
spec.updateStrategy field
RollingUpdateOnDeleteRollingUpdate:
maxSurge: 0
maxUnavailable
1;maxSurge:0;maxUnavailable>node_number
Recreate; replace all ds# demo-ds-rollingupdate.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: demo-ds-rollingupdate
spec:
minReadySeconds: 30
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
selector:
matchLabels:
app: monitor
template:
metadata:
labels:
app: monitor
spec:
containers:
- name: monitor
image: busybox
command:
- sleep
- infinity
kubectl apply -f demo-ds-rollingupdate.yaml
# daemonset.apps/demo-ds-rollingupdate created
# update image
kubectl set image ds demo-ds-rollingupdate monitor=busybox:1.36
# daemonset.apps/demo-ds-rollingupdate image updated
# confirm:
# update one by one
# avaiable every 30s
kubectl get ds -w
# NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
# demo-ds-rollingupdate 2 2 2 2 2 <none> 86s
# demo-ds-rollingupdate 2 2 2 2 2 <none> 102s
# demo-ds-rollingupdate 2 2 2 0 2 <none> 102s
# demo-ds-rollingupdate 2 2 1 1 1 <none> 2m12s
# demo-ds-rollingupdate 2 2 2 1 1 <none> 2m15s
# demo-ds-rollingupdate 2 2 2 1 2 <none> 2m45s
# demo-ds-rollingupdate 2 1 1 1 1 <none> 3m16s
# demo-ds-rollingupdate 2 2 1 2 1 <none> 3m16s
# demo-ds-rollingupdate 2 2 2 2 1 <none> 3m20s
# demo-ds-rollingupdate 2 2 2 2 2 <none> 3m50s
OnDelete:
ds controller waits for manual Pod deletion, and then replaces it with a new Pod
Pods with much more control# demo-ds-ondelete.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: demo-ds-ondelete
spec:
minReadySeconds: 30
updateStrategy:
type: OnDelete # strategy
selector:
matchLabels:
app: monitor
template:
metadata:
labels:
app: monitor
spec:
containers:
- name: monitor
image: busybox
command:
- sleep
- infinity
kubectl apply -f demo-ds-ondelete.yaml
# daemonset.apps/demo-ds-ondelete created
kubectl get ds
# NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
# demo-ds-ondelete 2 2 2 2 2 <none> 41s
kubectl set image ds demo-ds-ondelete monitor=busybox:1.36
# daemonset.apps/demo-ds-ondelete image updated
no ds get updated unless manually gets deleted
kubectl get pod
# NAME READY STATUS RESTARTS AGE
# demo-ds-ondelete-4qvl6 1/1 Running 0 99s
# demo-ds-ondelete-wxlnm 1/1 Running 0 99s
# manually delete
kubectl delete po demo-ds-ondelete-4qvl6 --wait=false
# pod "demo-ds-ondelete-4qvl6" deleted
# confirm
kubectl get ds -w
# NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
# demo-ds-ondelete 2 2 2 2 2 <none> 96s
# demo-ds-ondelete 2 2 2 2 2 <none> 108s
# demo-ds-ondelete 2 2 2 0 2 <none> 108s
# demo-ds-ondelete 2 2 1 1 1 <none> 3m44s
# demo-ds-ondelete 2 2 2 1 1 <none> 3m48s
# demo-ds-ondelete 2 2 2 1 2 <none> 4m18s
# confirm
kubectl get pod
# NAME READY STATUS RESTARTS AGE
# demo-ds-ondelete-bd9lg 1/1 Running 0 99s
# demo-ds-ondelete-wxlnm 1/1 Running 0 5m23s
# manually delete another one
kubectl delete po demo-ds-ondelete-wxlnm --wait=false
# pod "demo-ds-ondelete-wxlnm" deleted
# confirm
kubectl get ds -w
# NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
# demo-ds-ondelete 2 2 1 2 1 <none> 7m17s
# demo-ds-ondelete 2 2 2 2 1 <none> 7m21s
# demo-ds-ondelete 2 2 2 2 2 <none> 7m51s