A DaemonSets are like ReplicaSets, as it helps you deploy multiple instances of the pod, but it runs one pod on each node in the cluster. Whenever a new node is added to the cluster, a DaemonSet pod is automatically added to that node, and when a node is removed DaemonSet pod automatically removed. A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. As nodes are added to the cluster, Pods are added to them. As nodes are removed from the cluster, those Pods are garbage collected. Deleting a DaemonSet will clean up the Pods it created.
Some typical uses of a DaemonSet are:
- running a cluster storage daemon on every node
- running a logs collection daemon on every node
- running a node monitoring daemon on every node
In the Kubernetes architecture, Kube-proxy is required on every node in the cluster. That is one good use case of demonSets. The Kube-proxy component can be deployed as a daemonSet in the cluster.
apiVersion: apps/v1 kind: DaemonSet metadata: name: nginx-daemonset labels: app: nginx spec: selector: matchLabels: app: nginx template: metadata: name: nginx-pod labels: app: nginx spec: containers: - name: nginx-container image: nginx ports: - containerPort: 80 protocol: TCP
$ kubectl create -f nginx-daemonsets.yaml daemonset.apps/nginx-daemonset created $ kubectl get daemonset NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE nginx-daemonset 1 1 1 1 1 <none> 15s $ kubectl get pods NAME READY STATUS RESTARTS AGE nginx-daemonset-ml7rk 1/1 Running 0 33s
- Minikube has one node thus, the pod is only one.