This lesson explores DaemonSets in Kubernetes, covering creation, namespaces, pod scheduling, and deploying a logging DaemonSet with Fluentd and Elasticsearch.
In this lesson, we explore DaemonSets in a Kubernetes cluster. We will answer key questions about creating DaemonSets, their namespaces, and pod scheduling. In addition, you’ll learn how to deploy a logging DaemonSet using Fluentd and Elasticsearch.
The NAMESPACE column in the output above shows that both DaemonSets are deployed in kube-system. To further validate that no DaemonSets are running in the default namespace, run:
Copy
Ask AI
root@controlplane:~# kubectl get daemonsetsNo resources found in default namespace.
Running the following command again:
Copy
Ask AI
root@controlplane:~# kubectl get daemonsets -A
confirms that the only active DaemonSets are in the kube-system namespace:
Copy
Ask AI
NAMESPACE NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTORkube-system kube-flannel-ds 1 1 1 1 1 <none>kube-system kube-proxy 1 1 1 1 1 kubernetes.io/os=linux
Thus, the kube-flannel-ds and kube-proxy are the only DaemonSets running in the cluster.
In this section, you’ll deploy a DaemonSet for logging using Fluentd and Elasticsearch. There are two common methods to obtain the DaemonSet specification.
Since Kubernetes doesn’t offer a direct command for creating a DaemonSet, you can start by generating a deployment manifest in dry-run mode and then convert it. Run:
Edit the generated fluentd.yaml file to change the kind from Deployment to DaemonSet and remove the replicas and strategy fields, so it closely resembles:
After making the necessary modifications, create the DaemonSet:
Copy
Ask AI
kubectl create -f fluentd.yaml
Verify the newly created DaemonSet by listing all DaemonSets in the kube-system namespace:
Copy
Ask AI
kubectl get ds -n kube-system
The output should resemble:
Copy
Ask AI
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGEelasticsearch 1 1 1 0 <none> <none> 10skube-flannel-ds 1 1 1 1 <none> <none> 29mkube-proxy 1 1 1 1 kubernetes.io/os=linux 29m
The example provided represents a basic logging configuration. Be sure to customize resource limits, volume mounts, and other parameters to match your production environment.
This concludes the lab on DaemonSets in Kubernetes. You learned how to list and inspect DaemonSets, examine their node scheduling, and deploy a new DaemonSet specifically for logging purposes.For further details on Kubernetes concepts and best practices, explore the following resources: