Detailed explanation of daemonset, resource controller of kubernetes k8s



Detailed explanation and example of daemonset of kubernetes resource controller


Host configuration planning

Server name (host name) System version to configure Intranet IP Internet IP (Analog)
k8s-master CentOS7.7 2C/4G/20G
k8s-node01 CentOS7.7 2C/4G/20G
k8s-node02 CentOS7.7 2C/4G/20G


What is a controller

Kubernetes has many controllers built in, which are equivalent to a state machine to control the specific state and behavior of pod.

Some controller types are as follows:
  • Replicationcontroller and replicaset
  • Deployment
  • DaemonSet
  • StatefulSet
  • Job/CronJob
  • HorizontalPodAutoscaler



Daemonset ensures that a copy of the pod runs on all (or some) nodes. When a node joins the cluster, a pod is added for them. When a node is removed from the cluster, the pods are also recycled. Deleting daemonset will delete all pods it creates.

Some typical uses of daemonset are as follows:
  • Run cluster storage daemonset on each node, such as glusterd and CEPH.
  • Run the journal collection daemonset on each node, such as fluent, logstash.
  • Run a monitoring daemonset on each node, such as Prometheus node exporter, flowmill, sysdig agent, collected, dynatrace oneagent, appdynamics agent, datadog agent, new relic agent, ganglia gmond, or instana agent.

A simple usage is to start a daemonset on all nodes and use it as a daemon of each type.

A slightly more complex usage is to use a daemonset for each of the daemon types individually. In this way, there are multiple daemonsets with different identities, and different memory and CPU requirements for different hardware types.

Note: the pods in daemonset can use hostport, so the pod can be accessed through the node IP; because the pod will not be scheduled to other nodes in daemonset mode. Examples are as follows:

     - name: httpd
       containerPort: 80
       #Do not specify a hostport for the pod unless absolutely necessary. When you bind a pod to a hostport, it limits the number of locations that the pod can schedule, except for daemonset
       #Generally, containerport has the same value as hostport
       Hostport: 8090 ා the pod can be accessed by host + hostport. For example, if the pod is scheduled to k8s-node02 [], the pod can be accessed through
       protocol: TCP


Please refer to “kubernetes k8s’s creation of pod through yaml and details of common fields of pod file”


Daemonset example

Yaml file

[[email protected] controller]# pwd
 [[email protected] controller]# cat daemonset.yaml 
 apiVersion: apps/v1
 kind: DaemonSet
   name: fluentd-elasticsearch
   namespace: default
     k8s-app: fluentd-logging
       name: fluentd-elasticsearch
         name: fluentd-elasticsearch
       #Allow to run in master node
       - key:
         effect: NoSchedule
       - name: fluentd-elasticsearch
             cpu: 1
             memory: 200Mi
             cpu: 100m
             memory: 200Mi
         - name: varlog
           mountPath: /var/log
         - name: varlibdockercontainers
           mountPath: /var/lib/docker/containers
           readOnly: true
       #Elegant close application, time setting. After this time, the [optional] will be forced off, and the default is 30 seconds
       terminationGracePeriodSeconds: 30
       - name: varlog
           path: /var/log
       - name: varlibdockercontainers
           path: /var/lib/docker/containers


Run daemonset and view the status

[[email protected] controller]# kubectl apply -f daemonset.yaml 
 daemonset.apps/fluentd-elasticsearch created
 [[email protected] controller]# 
 [[email protected] controller]# kubectl get daemonset -o wide
 NAME                    DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE   CONTAINERS              IMAGES                                                            SELECTOR
 fluentd-elasticsearch   3         3         3       3            3                     92s   fluentd-elasticsearch   name=fluentd-elasticsearch
 [[email protected] controller]# 
 [[email protected] controller]# kubectl get pod -o wide
 NAME                          READY   STATUS    RESTARTS   AGE   IP            NODE         NOMINATED NODE   READINESS GATES
 fluentd-elasticsearch-52b8z   1/1     Running   0          95s   k8s-node02              
 fluentd-elasticsearch-fps95   1/1     Running   0          95s   k8s-master              
 fluentd-elasticsearch-pz8j7   1/1     Running   0          95s   k8s-node01

It can be seen from the above that all nodes in the k8s cluster, including the master node, run the daemonset pod.


Related reading

1. Kubernetes k8s create pod through yaml and explain the common fields of pod file

2. Resource controller RC, RS and deployment of kubernetes k8s

3. Detailed explanation of resource controller statefulsets of kubernetes k8s






If you think it’s good, pay attention to it!


Recommended Today

Api: tiktok: user video list

Tiktok tiktok, tiktok, tiktok, Api, Api, jitter, voice, bullet screen comments, jitter, jitter, and jitter. Tiktok tiktok tiktok data, jitter data acquisition, live broadcast of shaking sound Titodata: professional short video data acquisition and processing platform. For more information, please contact:TiToData Massive data collection Collect 500 million pieces of data for customers every day Tiktok […]