1. 概念
1.1 功能:
- 維護忧陪、管理pod的生命周期
- 每個適合的節(jié)點上運行一個該pod 抓谴。
說明:當(dāng)節(jié)點加入到K8S集群中魂挂,pod會被(DaemonSet)調(diào)度到該節(jié)點上運行链患,當(dāng)節(jié)點從K8S集群中被移除吸占,被DaemonSet調(diào)度的pod會被移除晴叨。
1.2 一般應(yīng)用
日志收集、監(jiān)控采集矾屯、分布式存儲守護進程兼蕊、ingress等
1.3 比較
對象 | 是否有狀態(tài) | POD數(shù)量 |
---|---|---|
Deployment | 無 | 按副本數(shù) |
DaemonSet | 無 | (適合節(jié)點)每節(jié)點一個 |
StatefulSet | 有 | 按副本數(shù) |
相關(guān)文檔
《K8S-Deployment》
《k8s-StatefulSet》
2. 示例
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:
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: fluentd-elasticsearch
image: k8s.gcr.io/fluentd-elasticsearch:1.20
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath: