What is a Kubernetes DaemonSet?
A Kubernetes 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.
Why use a DaemonSet?
There are a number of use cases for DaemonSets, including:
Running a cluster storage daemon, such as glusterd, ceph, or rook-minio, on each node.
Running a logs collection daemon, such as fluentd or filebeat, on each node.
Running a node monitoring agent, such as Prometheus Node Exporter, on each node.
Creating a DaemonSet
A DaemonSet can be created with the kubectl create command. The following command creates a DaemonSet named my-ds, which runs the nginx container on each node in the cluster:
$ kubectl create daemonset my-ds –image=nginx
Checking DaemonSet Status
After creating a DaemonSet, you can check its status with the kubectl get daemonset command:
$ kubectl get daemonset my-ds
Updating a DaemonSet
You can update a DaemonSet by changing its specification in the same way that you would change any other type of Kubernetes object. For example, the following command updates the my-ds DaemonSet to use the busybox image:
$ kubectl apply -f my-ds-v2.yaml
Deleting a DaemonSet
You can delete a DaemonSet in the same way that you delete any other type of Kubernetes object. The following command deletes the my-ds DaemonSet:
$ kubectl delete daemonset my-ds