一個DaemonSet對象能確保其建立的Pod在集羣中的每一臺(或指定)Node上都運行一個副本。node
若是集羣中動態加入了新的Node,DaemonSet中的Pod也會被添加在新加入Node上運行。刪除一個DaemonSet也會級聯刪除全部其建立的Pod。下面是一些典型的DaemonSet的使用場景:git
下面的描述文件建立了一個運行着fluentd-elasticsearch鏡像的DaemonSet對象:github
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:
path: /var/lib/docker/containers
在Kubernetes 1.8以後,必須指定.spec.selector
來肯定這個DaemonSet對象管理的Pod,一般與.spec.template.metadata.labels
中定義的Pod的label一致。docker
.spec.template.spec.nodeSelector
或
.spec.template.spec.affinity
,DaemonSet Controller會將Pod建立在特定的Node上。
unschedulable
屬性會被DaemonSet Controller忽略。