Kubernetes DaemonSets: Explained and Guide to Create One

In this blog, we will learn about a basic understanding of Kubernetes DaemonSets and how to create DaemonSets on Kubernetes.

What is DaemonSets?

DaemonSet is an object of Kubernetes, which is deployed in every cluster node. When a pod is deployed as a DaemonSet, the pod deploys a copy of it in every available node in the cluster.

Some examples of DaemonSets are kube-proxy, and any logging or monitoring agent installed in the cluster.

You can list the available DaemonSets in your cluster using the following command

kubectl get daemonset -A

This command will list the available DaemonSets on all namespaces as shown below

Command to list the daemonset pods

And if you want to list the nodes the DaemonSet pod is running on, run the following command

kubectl get pods -l k8s-app=kube-proxy -o wide -n kube-system

This command will list the nodes in which the DaemonSet pod kube-proxy is running as shown below

command to list the nodes in which the demonset pod is running

How to Create DaemonSet

First, create a manifest file daemonset.yaml and copy the content given below

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

This file will deploy a DaemonSet of Nginx on the default namespace on all available nodes.

Run the following command to deploy the DaemonSet

kubectl apply -f daemonset.yaml

Once it is deployed you can verify if it’s deployed as DaemonSet using the command

kubectl get po -o wide
command to list the nodes in which the nginx demonset pod is running

Conclusion

In summary, we have learned about DaemonSets and how to create one.

I believe this blog gives you a basic understanding of DaemonSets.

Other Interesting Blogs

Leave a Comment

Share via
Copy link
Powered by Social Snap