DaemonSets

Like other workload objects, DaemonSets manage groups of replicated Pods.

However, DaemonSet ensures that all or selected Worker Nodes run a copy of a Pod (one-Pod-per-node).

As you add nodes, DaemonSets automatically add Pods to the new nodes. As the nodes removed from the cluster, those Pods are garbage collected.

DaemonSets use a Pod template, which contains a specification for its Pods. The Pod specification determines how each Pod should look: what applications should run inside its containers, which volumes it should mount, its labels and selectors, and more.

Here is the configuration of DaemonSet:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd
  namespace: kube-system
  labels:
    k8s-app: fluentd
spec:
  selector:
    matchLabels:
      name: fluentd
  template:
    metadata:
      labels:
        name: fluentd
    spec:
      containers:
      - name: fluentd-elasticsearch
        image: k8s.gcr.io/fluentd-elasticsearch:1.20

Create DaemonSet

$ kubectl create -f daemonset.yaml 
daemonset.apps "fluentd" created

Check pods

$ kubectl get pods -n kube-system
NAME             READY     STATUS    RESTARTS   AGE
fluentd-7svlj    1/1       Running   0          58s
fluentd-kwm4x    1/1       Running   0          58s
fluentd-q64wf    1/1       Running   0          58s

Check No.of nodes

$ kubectl get nodes
NAME                                       STATUS    ROLES       AGE VERSION
gke-cluster-1-default-pool-a6a57f2a-77wb   Ready     < none >    6h  v1.11.6-gke.2
gke-cluster-1-default-pool-a6a57f2a-xkgz   Ready     < none >    6h  v1.11.6-gke.2
gke-cluster-1-default-pool-a6a57f2a-z2bx   Ready     < none >    6h  v1.11.6-gke.2

 

Some uses of a DaemonSet are:

  • running a cluster storage daemon, such as glusterd, ceph, on each node.
  • running a logs collection daemon on every node, such as fluentd or logstash.
  • running a node monitoring daemon on every node, such as Prometheus Node Exporter, AppDynamics Agent, Datadog agent, New Relic agent etc.

Running Pods on Only Some Nodes

If you specify a .spec.template.spec.nodeSelector, then the DaemonSet controller will create Pods on nodes which match that node selector.

spec:
   nodeSelector:
      type: prod

Likewise if you specify a .spec.template.spec.affinity, then DaemonSet controller will create Pods on nodes which match that node affinity.

spec:
  tolerations:
    - key: node-role.kubernetes.io/master
      effect: NoSchedule

If you do not specify either, then the DaemonSet controller will create Pods on all nodes.

 

Advertisements