DaemonSets

A DaemonSet runs exactly one copy of a Pod on every node (or a selected subset).

Sometimes you need a Pod on every node β€” not a fixed count, but one per machine. That is what a DaemonSet does.

Typical uses

  • Log collectors (like Fluent Bit) that gather logs from each node.
  • Monitoring agents (like a node exporter) that report node metrics.
  • Networking or storage daemons that must run cluster-wide.

How the count works

You do not set replicas. As nodes join the cluster, the DaemonSet automatically adds a Pod to each; as nodes leave, their Pods are removed. You can restrict it to certain nodes with a nodeSelector or tolerations.

Example

Example Β· yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: node-logger
spec:
  selector:
    matchLabels:
      app: node-logger
  template:
    metadata:
      labels:
        app: node-logger
    spec:
      containers:
        - name: fluent-bit
          image: fluent/fluent-bit:3.0
          volumeMounts:
            - name: varlog
              mountPath: /var/log
      volumes:
        - name: varlog
          hostPath:
            path: /var/log

When to use it

  • A platform team deploys a log collector DaemonSet so every node ships its container logs to a central Elasticsearch cluster automatically.
  • A security team runs a vulnerability scanner DaemonSet that checks every node's running containers and reports findings to a dashboard.
  • A network team uses a DaemonSet to deploy a CNI plugin agent to every node so pod networking works uniformly across the cluster.

More examples

Log-collector DaemonSet

Deploys a Fluentd log collector to every node, mounting the host /var/log directory to ship node and container logs.

Example Β· yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd
  namespace: kube-system
spec:
  selector:
    matchLabels:
      name: fluentd
  template:
    metadata:
      labels:
        name: fluentd
    spec:
      containers:
        - name: fluentd
          image: fluentd:v1.16
          volumeMounts:
            - name: varlog
              mountPath: /var/log
      volumes:
        - name: varlog
          hostPath:
            path: /var/log

Verify DaemonSet pod placement

Confirms the DaemonSet has one desired pod per node, and that all pods are current and ready.

Example Β· bash
kubectl get ds -n kube-system
# NAME      DESIRED   CURRENT   READY   NODE SELECTOR
# fluentd   3         3         3       <none>

kubectl get pods -n kube-system -l name=fluentd -o wide
# One pod per node

Limit DaemonSet to specific nodes

Restricts DaemonSet pod scheduling to nodes with matching labels, useful for GPU-specific or OS-specific agents.

Example Β· yaml
spec:
  template:
    spec:
      nodeSelector:
        kubernetes.io/os: linux
        node-role: gpu-worker
      containers:
        - name: gpu-monitor
          image: gpu-monitor:1.0

Discussion

  • Be the first to comment on this lesson.
DaemonSets β€” Kubernetes | SoundsCode