Pod控制器中的DaemonSet的作用就是涩禀,確保全部或者某些節(jié)點(diǎn)上保證運(yùn)行一個(gè)副本才睹,當(dāng)有新節(jié)點(diǎn)加入的時(shí)候奖亚,同時(shí)也會新增加一個(gè)節(jié)點(diǎn)淳梦。一般應(yīng)用的場景有日志收集(fluentd、logstash)昔字、監(jiān)控(Prometheus node exporter)等等爆袍。
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: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
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
在默認(rèn)情況下是不會在master節(jié)點(diǎn)上創(chuàng)建pod的,因?yàn)閙aster節(jié)點(diǎn)是污點(diǎn)節(jié)點(diǎn)李滴,除非特別指定了spec.template.spec.tolerations
螃宙。
更新
關(guān)于更新策略,和其他控制器一樣有兩個(gè)字段 分別是 :RollingUpdata
OnDelete
所坯。
OnDelete
意為在刪除時(shí)更新Pod
RollingUpdata
是滾動(dòng)更新 ,而 RollingUpdata
中只有maxUnavailable
字段挂捅,是因?yàn)镈aemonSet只允許在期望的節(jié)點(diǎn)上運(yùn)行一個(gè)pod芹助,所以他只能先刪再創(chuàng)建。
更新代碼示例:
kubectl set image daemonset filebeat-da filebeat=ikubernetes/filebeat:5.5.6-alpine