Running a daemonset on all nodes of a kubernetes cluster
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Running a daemonset on all nodes of a Kubernetes cluster is an essential strategy for deploying common components across the entire cluster, such as log collectors, monitoring agents, or networking components. DaemonSets ensure that a copied pod runs on every node which meets specific criteria, enabling cluster-wide functionalities in a manageable way.
Understanding DaemonSets
A DaemonSet in Kubernetes ensures that all (or some) nodes in a cluster run a copy of a specific pod. When nodes are added to the cluster, the daemonset controller automatically schedules pods on them. If nodes are removed from the cluster, those pods are garbage collected. Deleting a DaemonSet will also remove the associated pods.
Use Cases for DaemonSets
- Log collection: Running a log collection agent, such as Fluentd or Logstash, on every node.
- Node monitoring: Deploying monitoring tools, like Prometheus Node Exporter, to collect metrics from each node.
- Network solutions: Implementing network plugins or load balancers that require an instance on each node.
Creating a DaemonSet
To create a DaemonSet, you define a YAML manifest that specifies the desired behavior. Here’s a basic example of a DaemonSet manifest:
- name: example-container
- `apiVersion`: Specifies the API version. For DaemonSets, it typically is `apps/v1`.
- `kind`: Indicates that this Kubernetes object is a DaemonSet.
- `metadata`: Includes details such as the name of the DaemonSet.
- `spec`: Contains the definition of the DaemonSet, including the pod template and selector definitions.
- Create a DaemonSet: Deploy using the command `kubectl apply -f daemonset.yaml`.
- List DaemonSets: Retrieve a list of all DaemonSets using `kubectl get daemonsets`.
- Delete a DaemonSet: Remove a DaemonSet and its pods with `kubectl delete daemonset example-daemonset`.
- matchExpressions:
- key: kubernetes.io/e2e-az-name
- e2e-az1
- When a new node joins the cluster, the DaemonSet controller checks if the node satisfies the selectors and schedules the pod if necessary.
- For existing nodes, any changes to selector conditions will not trigger existing DaemonSet pods to be re-evaluated or moved.

