Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

DaemonSet of Kubernetes resource object

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

DaemonSet is a new resource object in Kubernetes1.2 version.

DaemonSet allows all (or some specific) Node nodes to run only one Pod. When a node joins the kubernetes cluster, Pod is scheduled to run on the node (DaemonSet). When the node is removed from the kubernetes cluster, the Pod scheduled by (DaemonSet) is removed. If DaemonSet is deleted, all pods related to this DaemonSet will be deleted.

When using kubernetes to run applications, we often need to run the same daemon (pod) on one zone or all Node, such as the following scenario:

Each Node runs a distributed storage daemon, such as glusterd,ceph running log collector on each Node, for example, fluentd,logstash running monitoring on each Node, such as prometheus node exporter,collectd, etc.

DaemonSet's Pod scheduling strategy is very similar to RC. In addition to scheduling on each Node using the system's built-in scheduling algorithm, you can also use NodeSelector or NodeAffinity in the Pod definition to specify the Node range that meets the conditions.

DaemonSet resource file format

ApiVersion: extensions/v1beta1kind: DaemonSet metadata:

1. The following example is defined as launching a filebeat container on each Node where the host directory "/ var/log/messages" is mounted

$vi k8s-log-filebeat.yamlapiVersion: v1kind: ConfigMap # define the content of a config file metadata: name: k8s-logs-filebeat-config namespace: kube-systemdata: # fill in filebeat to read log related information filebeat.yml:-filebeat.prospectors:-type: log paths:-/ messages fields: app: K8s type: module fields_under_root: true Output.logstash: # specified logstash port (by default 5044) hosts: ['10.0.0.100 hosts 5044']-apiVersion: apps/v1kind: DaemonSet # DaemonSet object Make sure to run a copy of metadata: name: k8s-logs namespace: kube-systemspec: selector: matchLabels: project: K8s app: filebeat template: metadata: labels: project: K8s app: filebeat spec: containers:-name: filebeat image: docker.elastic.co/beats/filebeat:6.8.1 args: ["- c", "/ etc/filebeat.yml" on each node node "- e" ] resources: requests: cpu: 100m memory: 100Mi limits: cpu: 500m memory: 500Mi securityContext: runAsUser: 0 # perform the actual mount operation volumeMounts: # Mount the configuration in configmap to the / etc/filebeat.yml file -name: filebeat-config mountPath: / etc/filebeat.yml subPath: filebeat.yml # Mount the host / var/log/messages path to / messages-name: k8s-logs mountPath: / messages # define the volume volumes:-name: k8s-logs hostPath: path: / var/log/messages type: File-name: filebeat-config configMap: name: k8s-logs-filebeat-config

two。 Use the kubectl create command to create the DeamonSet

$kubectl create-f k8s-log-filebeat.yamlconfigmap/k8s-logs-filebeat-config createddaemonset.apps/k8s-logs created

3. Looking at the created DeamonSet and Pod, you can see that a Pod has been created on each Node

$kubectl get ds-n kube-system | grep "k8s-logs" NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGEk8s-logs 2 20 20 2m15s $kubectl get pods-n kube-system-o wide | grep "k8s-logs" k8s-logs-gw4bs 0/1 Running 0 87s k8s-node01 k8s-logs-p6r6t 0/1 Running 0 87s k8s-node02

In kubernetes versions later than 1.6, DaemonSet can also perform a rolling upgrade, that is, when updating a DaemonSet template, the old Pod copy will be automatically deleted and the new Pod copy will be automatically created. In this case, the update policy (updateStrategy) of DaemonSet is RollingUpdate, as follows:

ApiVersion: apps/v1kind: DaemonSet metadata: name: k8s-logs namespace: kube-systemspec: updateStrategy: type: RollingUpdate

Another value of updateStrategy is OnDelete, that is, a new copy of Pod will be created only if the copy created by DaemonSet is manually deleted. If you do not set the value of updateStrategy, it will be set to RollingUpdate by default in versions after kubernetes 1.6 (rolling upgrade).

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report