DaemonSets in Kubernetes Cluster
Like other controllers, DaemonSets manage groups of replicated Pods.
However, DaemonSet ensures that all or selected Worker Nodes run a copy of a Pod (one-Pod-per-node).
As you add nodes, DaemonSets automatically add Pods to the new nodes. As the nodes are removed from the cluster, those Pods are garbage collected.
Here is the manifest of DaemonSet:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd
namespace: kube-system
labels:
k8s-app: fluentd
spec:
selector:
matchLabels:
name: fluentd
template:
metadata:
labels:
name: fluentd
spec:
containers:
- name: fluentd
image: fluentd:latestCreate a daemonset:
kubectl create -f daemonset.yamldaemonset.apps "fluentd" createdCheck the pod running:
kubectl get pods -n kube-systemNAME READY STATUS RESTARTS AGE
fluentd-7svlj 1/1 Running 0 58s
fluentd-kwm4x 1/1 Running 0 58s
fluentd-q64wf 1/1 Running 0 58sCheck no. of nodes:
kubectl get nodes
NAME STATUS ROLES AGE VERSION
gke-cluster-1-default-pool-a6a57f2a-77wb Ready < none > 6h v1.11.6-gke.2
gke-cluster-1-default-pool-a6a57f2a-xkgz Ready < none > 6h v1.11.6-gke.2
gke-cluster-1-default-pool-a6a57f2a-z2bx Ready < none > 6h v1.11.6-gke.2Display your daemon sets:
kubectl get daemonsets
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE AGE
fluentd 3 3 3 3 3 5mGet details of a daemonset:
kubectl describe daemonset fluentdEdit a daemonset:
kubectl edit daemonset fluentdDelete a daemonset:
kubectl delete daemonset fluentd
daemonset.apps “fluentd” deletedSome uses of a DaemonSet are:
-
running a cluster storage daemon, such as glusterd, ceph, on each node.
-
running a logs collection daemon on every node, such as fluentd or logstash.
-
running a node monitoring daemon on every node, such as Prometheus Node Exporter, AppDynamics Agent, Datadog agent, New Relic agent, etc.
Running Pods on Only Some Nodes
If you specify a .spec.template.spec.mode selector, then the DaemonSet controller will create Pods on nodes which match that node selector.
spec:
nodeSelector:
environment: prodNow, If you mention a .spec.template.spec.affinity, then DaemonSet controller will be creating the Pods on nodes which will be matching the node affinity.
spec:
tolerations:
- key: node-role.kubernetes.io/master
effect: NoScheduleIn case you will not specify anything, then the controller will be creating Pods on every node of the cluster.
Additional Resources
For more information about DaemonSets, check out these resources:
- Kubernetes DaemonSet Documentation - Official Kubernetes documentation explaining DaemonSets in detail
- Understanding Kubernetes DaemonSets - A comprehensive guide covering DaemonSet use cases and implementation
