CKA Exam Notes Series Part 2: DaemonSets
- William B
- Jul 18
- 2 min read
A Daemonset is a mechanism that deploys a single pod on every worker-node in a Kubernetes cluster. If a new node is added, it automatically adds new pod to it. Similarly, if a node is removed it automatically removes it. This is done primarily for high availability purposes, as if one worker node was to fail, you would have other copies of the pod running in your cluster. DaemonSets are commonly used to deploy logging agents (like Fluentd) on each node to collect logs from all containers and forward them to a centralized logging system.
The 3 main benefits of DaemonSets:
Monitoring and Logging Agent: Deploying these agents as an daemonset ensures we get monitoring and logging data seamlessly without any interruption.
Kube-proxy: kube-proxy is one of the main component of k8-cluster which is required on every worker node, to make sure kube-proxy is present on every worker node we can deploy it as a daemonsets
Networking: Some networking solution required some agent to be deployed on every worker node, we can use daemonset to deployed it on every worker node
PS: Daemonsets ensure the deployment of pod on every single node in k8-cluster but not on the Tainted node like the master-node as it is tainted by default. To deploy pod on tainted nodes too we have to create Toleration for that node by specifying the taint name and type under toleration key in definition file

apiVersion: apps/v1
kind: DaemonSet
metadata:
name: my-monitoring-agent-ds
labels:
app: my-monitoring-agent
type: monitoring-agent
spec:
selector:
matchLabels:
app: my-monitoring-agent
type: monitoring-agent
template:
metadata:
name: my-monitoring-agent-pod
labels:
app: my-monitoring-agent
type: monitoring-agent
spec:
tolerations:
effect: NoSchedule
containers:
- name: nginx-container
image: nginx
The labels under .spec.selector.matchLabels and .spec.template.metadata.labels should be matching for the DaemonSet to select the fluentd pod.
.spec.template.spec field specifies the pod template for the pod to be created.
containers specifies the image to be run along with the volume name and its corresponding mountPath. mountPath specifies where in the container would the volume be mounted whereas the type of volume is specified in the volumes field, later.
terminationGracePeriodSeconds mentions the time allowed for graceful termination
volumes defines the hostPath volume type with the name: varlog. The path field shows the path on the host system which will be mounted on the container.
Creating Daemonsets and Managing it:
##creating daemonset
kubectl create -f my-webapp-ds.yaml
##obtaining daemonset details
kubectl get ds -n ##namespace##
kubectl describe ds -n ##namespace##
##deleting daemonset
kubectl delete ds
Comments