DaemonSets

A DaemonSet is a Kubernetes resource that ensures a specific pod runs on every node in a cluster. It’s like a manager that makes sure a particular task or service is always running on each worker node. So, if you have ten nodes, you’ll have ten copies of that pod, one on each node. It’s handy for things like logging or monitoring agents, where you want them to be everywhere your application is running. If you add more nodes to your cluster, the DaemonSet automatically deploys the pod to those nodes too. And if you remove nodes, it takes care of cleaning up the pods from those nodes as well. So, it’s a convenient way to ensure consistent deployment and management of essential services across your Kubernetes cluster.

DaemonSet Manifest:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd
  namespace: kube-system
  labels:
    k8s-app: fluentd
spec:
  selector:
    matchLabels:
      name: fluentd
  template:
    metadata:
      labels:
        name: fluentd
    spec:
      containers:
      – name: fluentd
        image: fluentd:latest

Creating a DaemonSet:

$ kubectl create -f daemonset.yaml

Checking Running Pods:

$ kubectl get pods -n kube-system

Checking Number of Nodes:

$ kubectl get nodes

Displaying DaemonSets:

$ kubectl get daemonsets

Getting Details of a DaemonSet:

$ kubectl describe daemonset fluentd

Editing a DaemonSet:

$ kubectl edit daemonset fluentd

Deleting a DaemonSet:

$ kubectl delete daemonset fluentd

Examples of DaemonSet Use Cases:

  • Running cluster storage daemons like glusterd or ceph on each node.
  • Deploying log collection daemons such as fluentd or logstash on every node.
  • Installing node monitoring daemons like Prometheus Node Exporter, AppDynamics Agent, Datadog agent, or New Relic agent on each node.

Running Pods on Selected Nodes:

If you specify .spec.template.spec.nodeSelector, the DaemonSet controller creates Pods only on nodes that match the specified node selector.

spec:
nodeSelector:
environment: prod

Similarly, if you specify .spec.template.spec.affinity, the DaemonSet controller creates Pods on nodes that match the specified affinity.

spec:
tolerations:
– key: node-role.kubernetes.io/master
effect: NoSchedule

If neither is specified, the DaemonSet controller creates Pods on all nodes.

Leave a Reply

Your email address will not be published. Required fields are marked *