Saiyam Pathak avatar
By Saiyam Pathak
Director of Technical Evangelism


Learn all about what DaemonSets are in Kubernetes and discover how you can create a DaemonSet in your YAML file.


What are DaemonSets?

In this video, we'll be going through DaemonSets. DaemonSets in Kubernetes ensure that a copy of the pod runs on all or some nodes. Whenever a new node joins, the same copy of the pod is pinned over there, and whenever a node is removed from the cluster, the pod also gets removed. The DaemonSet controller controls DaemonSet, which is scheduled on all the pods, except for the ones where you cannot schedule the pods, or it's not schedulable, like on a master node.

Let's first see what all DaemonSets we already have running on our cluster. We will use the kubectl get ds -A command. We already have a flannel, and a kube proxy DaemonSet, which runs on all the nodes, including the master one.

How to create a DaemonSet in Kubernetes?

Now, how to create a DaemonSet. I already have a YAML file. DaemonSet is created using a kind called DaemonSet. Again, it has metadata, then a selector section, and it selects the same parts defined in the template labels. Finally, in the spec section, what you have is the container. It is the actual container that we want to run across all the nodes, all the pods.

There can be a variety of use cases, if you want the storage DaemonSet to be present on all the nodes, or you want to collect some log information from all the nodes. Again, if there is some specified script that runs on all the nodes, or whenever a new node joins, you want to run that particular script across the nodes or do node monitoring. All these use cases are pointing towards DaemonSet.

We will see a fairly simple example to calculate the memory from each node. You can see the image in the container section of the yaml file, and let's run this. First, we will use the kubectl create -f ds.yaml command. We can see that the DaemonSet is created. Now, use the command kubectl get ds. Again, you can see that two DaemonSets are there. You can also have a node selector in place if you want to specify it on specific nodes. Generally, it will run on all the nodes.

Now use the command kubectl get pods, and you can see both the pods created by DaemonSets are running. If I see the logs for a pod of the Daemon set by using the kubectl logs -f , it tells me how many MB is free and runs every five seconds. It is the same for the other one as well. We can also see additional information using the kubectl get ds -owide command. It will show you the selector and where the image is getting used. Also, if I use the kubectl get pods -owide command, we'll see that it's running on different nodes. This is because whenever we join a new node, it'll create a new pod of the same configuration and template we specified in the DaemonSet configuration. If we remove that particular node, it will go off.


That's what DaemonSet is and is used for logging, monitoring, and storage or for other script purposes you want to run across the nodes. That's it for this lecture, see you in the next one.

Civo course complete badge

You've successfully completed our course on Kubernetes objects

We hope you enjoyed learning and encourage you to check out our other courses to further expand your knowledge on Kubernetes