22. Controller - DaemonSet
Table of contents
Summary
A DaemonSet is a controller that deploys pods to all nodes or a specific node group in a cluster.
Unlike other replication controllers, DaemonSets cannot be scheduled for failure - they must always run on every node.
When new nodes are added, DaemonSets automatically deploy pods to those nodes.
When nodes are removed, DaemonSets automatically delete the pods running on those nodes.
DaemonSets are commonly used for deploying system processes such as log collectors or monitoring agents, which need to run on every node in the cluster.
DaemonSet definition
ReplicaSet
| Deployment
|
DaemonSet example-1
Prepare test
Create DaemonSet by yaml
vim daemonset-exam.yaml
apiVersion: apps/v1 kind: DaemonSet metadata: name: daemonset-nginx spec: selector: matchLabels: app: webui template: metadata: name: nginx-pod labels: app: webui spec: containers: - name: nginx-container image: nginx:1.14
Turn on the watch mode for pods(T1)
watch kubectl get pods -o wide
Delete node3
kubectl delete nodes node3
enforce daemonset-exam.yaml
kubectl create -f daemonset-exam.yaml
Check the daemonset status again
kubectl get daemonset
Check the T1 watch again
test
Check the token list at Master
sudo kubeadm token list
Get a new token reissued.
sudo kubeadm token create --ttl 1h
Get a new hash code
sudo openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
Node3 re-register to Master
sudo kubeadm join (Master Ip Address):6443 --token (Token value) --discovery-token-ca-cert-hash sha256: (Token hash code)
Check the DaemonSet status at Master
T1(watch kubectl get pods -o wide)
deamonset status
kubectl get daemonset.apps
DaemonSet example-2: Rolling update & Rollback
Check the pods and daemonset status
Turn on watching mode to pods
Turn on watching mode to daemonset
Test
Change Nginx version to 1.15 in edit mode
kubectl edit daemonsets.app daemonset-nginx
... spec: containers: - image: nginx:1.14 # Change to nginx:1.15 imagePullPolicy: IfNotPresent name: nginx-container resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File ...
<!– <div class="video-container">
</div>
–>
Check the pods event
Pod in node3
…Pod in node2 …
Pod in node3 …
DaemonSet example-3: Rolling Rollback
Check the image version check within pod’s container
kubectl get daemonset.apps -o wide
Downgrade container image nginx to before current
```bash kubectl rollout undo daemonset daemons