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 evicted. Deleting a DaemonSet will clean up the Pods it created.
Some typical uses of a DaemonSet are:
- running a cluster storage daemon, such as
ceph, on each node.
- running a logs collection daemon on every node, such as
- running a node monitoring daemon on every node, such as Prometheus Node Exporter (
collectd, Datadog agent, New Relic agent, or Ganglia
In a simple case, one DaemonSet, covering all nodes, would be used for each type of daemon. A more complex setup might use multiple DaemonSets for a single type of daemon, but with different flags and/or different memory and cpu constraints for different hardware types.
Create a DaemonSet
In this scenario, we're going to create an
nginx DaemonSet. Initially, we'll run this on our worker nodes
(node01), but then we will manipulate the DaemonSet to get it to run on the master node too.
In your terminal, you'll see a file named
nginx-daemonset.yaml. This is the DaemonSet which we will be using to run
nginx across both of our nodes.
First, let's create all the prerequisites needed for this DaemonSet to run:
kubectl create -f nginx-ds-prereqs.yaml
Now we've created the namespace (and other prerequisites), let's inspect the manifest for the
cat nginx-daemonset.yaml; echo
As you can see, we're running a basic DaemonSet - in the
contino namespace - which exposes port
80 inside the container.
kubectl create -f nginx-daemonset.yaml
Now check the status of the DaemonSet:
kubectl get daemonsets -n contino