Kubernetes DaemonSet — Explained

What is a Kubernetes DaemonSet?

Where we can use DaemonSets?

  • To run a daemon for logs collection on each node, such as Fluentd and logstash.
  • To run a daemon for cluster storage like glusterd and ceph on each node.
  • To run a daemon which does logs rotation and cleaning log files.
  • To run a daemon that runs on each node, detects node problems and reports them to the api-server, like node-problem-detector.
  • To run a daemon for node monitoring on every note, such as Prometheus Node Exporter, collectd.
  • Even you can use for storing the cache across all the node, like if there is large file need to be accessible by the users, you can mount some cloud volume and expose it.

How to create a DaemonSet

apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: kube-system
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels:
name: fluentd-elasticsearch
spec:
containers:
- name: fluentd-elasticsearch
image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
  • template. this is a required field that specifies a pod template for the DaemonSet to use. Along with the required fields for containers, this template requires appropriate labels (.spec.template.metadata.labels). You should also remember that a pod template of your DaemonSet must have a RestartPolicy equal to Always, which defaults to Always if not specified.
  • selector. The selector for the pods managed by the DaemonSet. This value must be a label specified in the pod template. This value is fixed and cannot be changed after the initial creation of the DaemonSet. Changing this value will cause pods created via that DaemonSet to be orphaned. Kubernetes offers two ways to match matchLabels and matchExpressions for creating complex selectors.
  • template.spec.nodeSelector — This can be used to specify a subset of nodes that will create the Pod matching the specified selector.
  • template.spec.affinity — This field can be configured to set the affinity that would run the pod only on nodes that match the configured affinity.

Creating a DaemonSet

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
FoxuTech

FoxuTech

61 Followers

Discuss about #Linux, #DevOps, #Docker, #kubernetes, #HowTo’s, #cloud & IT technologies like #argocd #crossplane #azure https://foxutech.com/