Script Valley
Kubernetes: From Containers to Clusters
Scaling, Scheduling, and Resource ManagementLesson 5.4

Kubernetes DaemonSets: running one pod per node for monitoring and logging

DaemonSet definition, automatic scheduling on new nodes, typical use cases, DaemonSet vs Deployment, tolerations in DaemonSets, DaemonSet update strategy, nodeSelector in DaemonSets

DaemonSets Ensure Every Node Runs One Pod

Kubernetes DaemonSet one pod per node diagram

A DaemonSet ensures exactly one Pod runs on every node (or a subset of nodes). When a new node joins the cluster, the DaemonSet automatically schedules a Pod on it. When a node is removed, the Pod is garbage collected.

Common DaemonSet Use Cases

Log collectors (Fluentd, Fluent Bit), node monitoring agents (Prometheus Node Exporter), network plugins (CNI agents), storage drivers (Ceph), and security agents all run as DaemonSets.

DaemonSet Manifest

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: log-collector
  namespace: monitoring
spec:
  selector:
    matchLabels:
      app: log-collector
  template:
    metadata:
      labels:
        app: log-collector
    spec:
      tolerations:
      - key: node-role.kubernetes.io/control-plane
        operator: Exists
        effect: NoSchedule    # run on control-plane too
      containers:
      - name: fluent-bit
        image: fluent/fluent-bit:2.1
        volumeMounts:
        - name: varlog
          mountPath: /var/log
      volumes:
      - name: varlog
        hostPath:
          path: /var/log

DaemonSets tolerate the control-plane taint when you need the agent on all nodes, including masters. Without this toleration, control-plane nodes are skipped.

Up next

Kubernetes Jobs and CronJobs: running batch and scheduled workloads

Sign in to track progress