Skip to content

How to deploy DaemonSets Service in Kubernetes (K8s)?

Published: (2 min read)  at 06:57 AM

Lets get started:

DaemonSets in Kubernetes Cluster

Like other controllers, DaemonSets manage groups of replicated Pods.

However, DaemonSet ensures that all or selected Worker Nodes run a copy of a Pod (one-Pod-per-node).

As you add nodes, DaemonSets automatically add Pods to the new nodes. As the nodes are removed from the cluster, those Pods are garbage collected.

Here is the manifest of DaemonSet:

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

Create a daemonset:

kubectl create -f daemonset.yamldaemonset.apps "fluentd" created

Check the pod running:

kubectl get pods -n kube-systemNAME         READY  STATUS  RESTARTS AGE
fluentd-7svlj 1/1   Running     0   58s
fluentd-kwm4x 1/1   Running     0   58s
fluentd-q64wf 1/1   Running     0   58s

Check no. of nodes:

kubectl get nodes
NAME                 STATUS      ROLES        AGE            VERSION
gke-cluster-1-default-pool-a6a57f2a-77wb Ready < none > 6h v1.11.6-gke.2
gke-cluster-1-default-pool-a6a57f2a-xkgz Ready < none > 6h v1.11.6-gke.2
gke-cluster-1-default-pool-a6a57f2a-z2bx Ready < none > 6h v1.11.6-gke.2

Display your daemon sets:

kubectl get daemonsets
NAME     DESIRED CURRENT READY UP-TO-DATE   AVAILABLE AGE
fluentd    3        3      3      3           3        5m

Get details of a daemonset:

kubectl describe daemonset fluentd

Edit a daemonset:

kubectl edit daemonset fluentd

Delete a daemonset:

kubectl delete daemonset fluentd
daemonset.apps “fluentd” deleted

Some uses of a DaemonSet are:

  1. running a cluster storage daemon, such as glusterd, ceph, on each node.
  2. running a logs collection daemon on every node, such as fluentd or logstash.
  3. running a node monitoring daemon on every node, such as Prometheus Node Exporter, AppDynamics Agent, Datadog agent, New Relic agent, etc.

Running Pods on Only Some Nodes

If you specify a .spec.template.spec.mode selector, then the DaemonSet controller will create Pods on nodes which match that node selector.

spec:
  nodeSelector:
    environment: prod

Now, If you mention a .spec.template.spec.affinity, then DaemonSet controller will be creating the Pods on nodes which will be matching the node affinity.

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

In case you will not specify anything, then the controller will be creating Pods on every node of the cluster.

For Reference

DaemonSet

A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. As nodes are added to the cluster, Pods are added to…

kubernetes.io

What is Kubernetes DaemonSet? K8s DaemonSets Explained

In this blog post, we will discuss Kubernetes DaemonSet, including what it’s used for, how to create one, and how to…

www.bmc.com

If you find this article helpful then you can buy me a coffee.

Follow for more stories like this 😊/ GitHub.