QA
Intermediate LevelDocker & Deployment

What is a Kubernetes DaemonSet and when is it used?

❓ Interview Prompt: Explain DaemonSets, one-pod-per-node scheduling, node selector filtering, and use cases for log collectors and monitoring agents.

A DaemonSet ensures that exactly one copy of a Pod runs on every (or selected) node in the cluster. As nodes are added to the cluster, DaemonSet Pods are automatically scheduled on them.

How DaemonSets Differ from Deployments:

•
Deployments: Schedule N replicas wherever the scheduler decides — may concentrate on fewer nodes.
•
DaemonSets: Schedule 1 pod per node — guaranteed node-level coverage.

Common Use Cases:

1
Log Collection (Fluentd, Filebeat): Each node runs a log forwarder that reads container logs from /var/log/pods/ and ships to Elasticsearch/Loki.
2
Metrics Export (Prometheus node-exporter): Each node runs a metrics exporter scraping OS-level metrics (CPU, disk, memory).
3
Network Plugin (CNI agents): Calico/Cilium/Flannel agents must run on every node to configure networking.
4
Security Scanning (Falco, Wiz): Kernel-level security agents need privileged access on every node.
5
Storage Drivers (CSI node plugins): Need to run on every node that mounts volumes.

Node Filtering:

Use nodeSelector or nodeAffinity to run DaemonSet pods only on specific nodes (e.g., only GPU nodes).

Code Implementation Example

yaml
# DaemonSet: run Prometheus node-exporter on EVERY node
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: node-exporter
  namespace: monitoring
spec:
  selector:
    matchLabels:
      app: node-exporter
  template:
    metadata:
      labels:
        app: node-exporter
    spec:
      # Must tolerate master node taints if you want monitoring there too
      tolerations:
        - key: node-role.kubernetes.io/control-plane
          operator: Exists
          effect: NoSchedule
      containers:
        - name: node-exporter
          image: prom/node-exporter:v1.7.0
          ports:
            - containerPort: 9100
          # Mount host filesystem for accurate OS metrics
          volumeMounts:
            - mountPath: /host/proc
              name: proc
              readOnly: true
            - mountPath: /host/sys
              name: sys
              readOnly: true
      volumes:
        - name: proc
          hostPath:
            path: /proc
        - name: sys
          hostPath:
            path: /sys
💡DaemonSet deploys node-exporter on every node — includes control-plane toleration to monitor masters too.
🎯 Interview Key Takeaway

DaemonSets guarantee one-pod-per-node scheduling — use for node-level concerns: logging agents, monitoring exporters, CNI plugins, and security scanners.

#Kubernetes#DaemonSet#Node Exporter#Logging#Monitoring#Intermediate
Back to all Docker & Deployment Questions→

More Docker & Deployment Interview Questions

Beginner LevelDocker & Deployment

How do Docker Multi-Stage Builds minimize image size and improve security?

Beginner LevelDocker & Deployment

What is the difference between a Docker Container and a Virtual Machine (VM)?

Beginner LevelDocker & Deployment

What is the difference between a Docker Image and a Docker Container?