K8S对象-DaemonSet
1. 概念
1.1 功能
- 维护、管理pod的生命周期
- 每个适合的节点上运行一个该pod 。
说明:当节点加入到K8S集群中,pod会被(DaemonSet)调度到该节点上运行,当节点从K8S集群中被移除,被DaemonSet调度的pod会被移除。
1.2 一般应用
日志收集、监控采集、分布式存储守护进程、ingress等
1.3 比较
对象 | 是否有状态 | POD数量 |
---|---|---|
Deployment | 无 | 按副本数 |
DaemonSet | 无 | (适合节点)每节点一个 |
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: