Kuber­netes Dae­mon­Sets simplify the man­age­ment of ap­plic­a­tions or services that you need to run on each node in the cluster. Con­fig­ur­a­tion and changes to a DaemonSet are auto­mat­ic­ally applied to all nodes.

What are Kuber­netes Dae­mon­Sets?

Kuber­netes Dae­mon­Sets are resources that ensure that at least one instance of a specific pod runs on every node in the cluster. The ap­plic­a­tion or service is therefore globally present in the entire cluster en­vir­on­ment. Dae­mon­Sets are par­tic­u­larly suitable for tasks such as mon­it­or­ing, logging or network services that must be available on every node in the cluster. A major advantage of Dae­mon­Sets is their scalab­il­ity, as they auto­mat­ic­ally start pods and delete existing pods when nodes fail or are removed. As a result, Dae­mon­Sets improve re­li­ab­il­ity and make cluster man­age­ment easier.

Tip

With the cloud managed Kuber­netes solution from IONOS, you benefit from a fully automated cluster setup, as well as high-per­form­ance workloads and fail safety.

How to configure Kuber­netes DaemonSet

Pod dis­tri­bu­tion is gran­u­larly con­trol­lable based on node prop­er­ties, resource re­quire­ments or other user-defined criteria. Here, we explain how to set up and use a DaemonSet.

Create a DaemonSet YAML file

First, you must define the con­fig­ur­a­tion of the DaemonSet in a YAML file. This file contains in­form­a­tion such as the name of the DaemonSet, the type of pod used and the specific settings for placement on the nodes.

Here’s an example of a YAML file that creates a pod with an NGINX container on each node:

apiVersion: apps/v1 
kind: DaemonSet 
metadata: 
    name: nginx-daemonset 
spec: 
    selector: 
        matchLabels: 
            app: nginx 
    template: 
        metadata: 
            labels: 
                app: nginx 
        spec: 
            containers: 
            - name: nginx-container 
                image: nginx:latest
yaml

Activate YAML con­fig­ur­a­tion

Open your command line and switch to the directory where your DaemonSet YAML file is located. Then execute the kubectl apply command to apply the con­fig­ur­a­tion to your Kuber­netes cluster:

kubectl apply -f daemonset.yaml
shell

This command tells the Kuber­netes cluster to create or update the resources defined in the YAML file.

Check the Kuber­netes Dae­mon­Sets

You should check whether the desired pods have been suc­cess­fully started on each node.

kubectl get daemonset
shell

The output of this command contains relevant in­form­a­tion, including:

  • DESIRED: The desired number of pods to be created by the DaemonSet.
  • CURRENT: The actual number of pods provided.
  • READY: The number of pods provided that are ready for operation.
  • UP-TO-DATE: The number of pods that are currently up to date in terms of DaemonSet con­fig­ur­a­tion.
  • AVAILABLE: The number of op­er­a­tion­al pods that are not affected by other resources, such as af­fin­it­ies or tol­er­ances.
  • NODE SELECTOR: Labels for nodes on which the DaemonSet is to run (if con­figured).
  • AGE: The time since the DaemonSet was created.

In our example, you can see that the Kuber­netes DaemonSet nginx-daemonset has three desired pods and three pods are currently running on the nodes.

NAME                      DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE 
nginx-daemonset              3         3        3         3            3          <none>       5m
shell

Check the pods

To get a more detailed view of the pods you have created, use this command:

kubectl get pods
shell

The output shows the status of the pods, including readiness, status and runtime.

NAME                      READY   STATUS    RESTARTS       AGE 
nginx-daemonset-abcde     1/1      Running      0          5m 
nginx-daemonset-fghij     1/1      Running      0          5m 
nginx-daemonset-klmno     1/1      Running      0          5m
shell

Delete a DaemonSet

First, you should check which Dae­mon­Sets are present in your cluster. Enter the command kubectl delete daemonset followed by the name of the DaemonSet to be deleted in the console. For example:

kubectl delete daemonset nginx-daemonset
shell

Limit Kuber­netes Dae­mon­Sets to specific nodes

To run Dae­mon­Sets on specific nodes in a Kuber­netes cluster, you can use node selectors or af­fin­it­ies in the DaemonSet con­fig­ur­a­tion. This allows you to specify the nodes on which the DaemonSet pods are to be created.

apiVersion: apps/v1 
kind: DaemonSet 
metadata: 
    name: nginx-daemonset 
spec: 
    selector: 
        matchLabels: 
            app: nginx 
    template: 
        metadata: 
            labels: 
                app: nginx 
        spec: 
            nodeSelector: 
                custom-label: special-node 
            containers: 
            - name: nginx-container 
                image: nginx:latest
yaml

In this example, the DaemonSet is con­figured so that it only runs on nodes with the label custom-label: special-node.

Com­mu­nic­ate with DaemonSet pods

There are different ways to com­mu­nic­ate with Daemon pods in Kuber­netes, depending on the re­quire­ments of your ap­plic­a­tion.

  • Push: In this case, the DaemonSet pods actively send data or updates to an external service, such as a stat­ist­ics database or a central log system. The DaemonSet pods them­selves have no clients and do not initiate any incoming con­nec­tions.
  • NodeIP and Known Port: With this method, each DaemonSet pod uses a specific port on the node to be reachable. Clients know the list of available node IPs and reach the pods via the cor­res­pond­ing node IP and port.
  • DNS: By using a __headless service__ with the same pod selector as the Kuber­netes DaemonSet, you can enable DNS res­ol­u­tion for the in­di­vidu­al pods. Clients can then com­mu­nic­ate with the DaemonSet pods using the Endpoints resource or by re­triev­ing multiple A records from the DNS.
  • Service: Creating a regular Kuber­netes service with the same pod selector gives clients access to the DaemonSet pods. This is done via the cluster IP address of the service. Note that this does not ensure that a specific node is reached. Instead, the service will forward the request to one of the available DaemonSet pods.

You can find more detailed in­form­a­tion on cluster man­age­ment for beginners in the Kuber­netes tutorial from our guide.

IONOS Cloud Managed Kuber­netes
Container workloads in expert hands

The ideal platform for demanding, highly scalable container ap­plic­a­tions. Managed Kuber­netes works with many cloud-native solutions and includes 24/7 expert support.

Go to Main Menu