Skip to main content
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.

1. Listing DaemonSets in All Namespaces

To begin, determine how many DaemonSets exist across all namespaces in your Kubernetes cluster. Execute the following command:
The output confirms that there are two DaemonSets in the cluster: kube-flannel-ds and kube-proxy, both located in the kube-system namespace:
Always verify the namespace of your DaemonSets to ensure proper deployment and troubleshooting.

2. Identifying the Namespace of DaemonSets

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:
Running the following command again:
confirms that the only active DaemonSets are in the kube-system namespace:
Thus, the kube-flannel-ds and kube-proxy are the only DaemonSets running in the cluster.

3. Examining Pod Scheduling for Kube-Proxy

To assess on how many nodes the pods managed by the kube-proxy DaemonSet are scheduled, start by reviewing the initial DaemonSet listing:
Notice that for kube-proxy, the desired, current, and ready counts are all one. For a deeper look into its configuration, run:
The detailed output confirms that exactly one node is scheduled for the kube-proxy pods:
To verify that your cluster has a single node, run:
Expected output:
This confirms that the kube-proxy DaemonSet is scheduled on one node, matching the cluster configuration.

4. Inspecting the Kubelet DaemonSet (Kube-Flannel)

To examine the specific image used by the kube-flannel-ds (managed as a DaemonSet by kubelet), run:
Within the output details of the pod template, locate the container image:
This confirms that the kube-flannel-ds uses the CoreOS Flannel image.
Ensuring the correct container image for your networking components is crucial for cluster stability.

5. Deploying a DaemonSet for Logging

In this section, you’ll deploy a DaemonSet for logging using Fluentd and Elasticsearch. There are two common methods to obtain the DaemonSet specification.

Option 1: Using an Official Sample from Documentation

Refer to the Kubernetes documentation for a sample DaemonSet YAML. Below is an example configuration:

Option 2: Converting a Deployment to a DaemonSet

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:
Verify the newly created DaemonSet by listing all DaemonSets in the kube-system namespace:
The output should resemble:
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:

Watch Video