DaemonSets
- Version
- 1.37
- Review
- Draft
Summary#
A DaemonSet runs one copy of a Pod on every eligible node, adding Pods as nodes join. It suits node-level agents such as log collectors and monitoring. nodeSelector or node affinity narrows the nodes, and tolerations allow Pods onto tainted nodes.
Syntax#
kubectl rollout status daemonset/NAME
spec:
template:
spec:
nodeSelector:
kubernetes.io/os: linux
tolerations:
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
Example#
A toleration with only operator: Exists matches every taint. Run this on a test cluster with at least one ready Linux node and enough resources to schedule one agent per Linux node.
(
set -eu
ns="ref-daemonsets-$$"
kubectl create namespace "$ns" >/dev/null
trap 'kubectl delete namespace "$ns" >/dev/null' EXIT
kubectl apply -n "$ns" -f - <<'EOF'
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-agent
spec:
selector:
matchLabels:
app: node-agent
template:
metadata:
labels:
app: node-agent
spec:
nodeSelector:
kubernetes.io/os: linux
tolerations:
- operator: Exists
containers:
- name: agent
image: registry.k8s.io/pause:3.10
EOF
kubectl rollout status -n "$ns" daemonset/node-agent --timeout=120s >/dev/null
nodes=$(kubectl get nodes -l kubernetes.io/os=linux \
-o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | sort)
placed=$(kubectl get -n "$ns" pods -l app=node-agent \
-o jsonpath='{range .items[*]}{.spec.nodeName}{"\n"}{end}' | sort)
if [ "$nodes" = "$placed" ]; then
echo "exactly one agent on every Linux node"
else
echo "agent placement differs from the node list"
fi
kubectl get -n "$ns" daemonset node-agent -o jsonpath='updateStrategy={.spec.updateStrategy.type}{"\n"}'
)
Expected output#
daemonset.apps/node-agent created
exactly one agent on every Linux node
updateStrategy=RollingUpdate
Common mistakes#
An untolerated NoSchedule taint blocks placement, which commonly affects control plane nodes. PreferNoSchedule is a preference. In a real manifest, tolerate only the taints the agent must run through.
Version applicability#
The example targets Kubernetes 1.37 and uses apps/v1, available since 1.9. The DaemonSet controller adds some tolerations automatically, such as those for unready and unschedulable nodes.
Sources#
- Attribution
- DevLookup contributors
- License
- CC-BY-4.0