What's a kubernetes DaemonSet?

2 min read | by Jordi Prats

When it comes to kubernetes objects, maybe the one that is quite common but still causes a lot of confusion is the DaemonSet. What's it's function?

A DaemonSet is a kubernetes object intended to make sure a pod is scheduled on every node of the cluster so that if we add a new node to the cluster, a new pod is going to be scheduled. On the other hand, if we remove one, the pod corresponding pod is going to be garbage collected

It's important to keep in mind that Daemonsets do respect normal scheduling rules: If a pod would not be scheduled in a specific node for whatever reason, a pod from DaemonSet neither would be: At the end of the day it's just another pod.

The most common use-case for DaemonSet are:

  • Log collection / aggregation
  • Node monitoring
  • Some cluster service that needs to be present on every node for pods to use (for example a storage provider such as iSCSI)

The DaemonSet it's quite similar to the Deployment definition. We'll have to make sure the selector is set correctly and we also have a template section to include the actual pod definition just as we would do on a Deployment:

apiVersion: apps/v1
kind: DaemonSet
  name: demo-ds
      component: pod-demo-ds
        component: pod-demo-ds
      - name: nginx
        image: nginx

The most notable exception is the absence of replicas which doesn't make sense on a DaemonSet since the number of replicas is determined by the number of nodes.

If we apply this definition on a tree node cluster:

$ kubectl get nodes
NAME           STATUS   ROLES                  AGE   VERSION
minikube       Ready    control-plane,master   54m   v1.20.0
minikube-m02   Ready    <none>                 51m   v1.20.0
minikube-m03   Ready    <none>                 49m   v1.20.0
$ kubectl apply -f ds-test.yaml 
daemonset.apps/demo-ds created

We will be able to see how it will create three pods:

$ kubectl get pods
demo-ds-mtknk   1/1     Running   0          3m
demo-ds-vtdpj   1/1     Running   0          3m
demo-ds-x8chm   1/1     Running   0          3m

DaemonSet respect taints and tolerations but have some extra tolerations described on the DaemonSet documentation

Posted on 04/06/2021