此文为学习《Kubernetes权威指南》的相关笔记
学习笔记:
常规的调度器调度方法并不能保证一组Pod副本被调度到不同的Node上,但在有些场景下,需要一批Node中都运行着一个Pod副本,书上给出的例子有:
在每个Node上运行一个GlusterFS或者Ceph存储的守护进程(存储需求)
在每个Node上运行一个日志采集程序,如Fluentd或者Logstach(日志需求)
在每个Node上运行一个性能监控程序,如collectd等(监控需求)
DaemonSet正式应对这种需求而生,它的调度策略与RC类似,可以使用内置调度算法在每个Node上实现调度
于此同时,DaemonSet也支持NodeSelector和Affinity亲和性调度策略对节点进行主动选择
简而言之,DaemonSet:在筛选后的每个Node上都调度一个Pod副本
阿里云大学云原生课程给出的DaemonSet的功能如下:
一个DaemonSet的配置文件如下
与大多数调度器一样,DaemonSet所属的apiVersion为apps/v1
其他语法格式与RC等调度器大致相同
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-cloud-logging
namespace: kube-system
labels:
k8s-app: fluentd-cloud-logging
spec:
updateStrategy:
type: RollingUpdate
selector:
matchLabels:
k8s-app: fluentd-cloud-logging
template:
metadata:
namespace: kube-system
labels:
k8s-app: fluentd-cloud-logging
spec:
containers:
- name: fluentd-cloud-logging
image: kayrus/fluentd-elasticsearch:1.20
imagePullPolicy: IfNotPresent
resources:
limits:
cpu: 100m
memory: 200Mi
env:
- name: FLUENTD_ARGS
value: -q
volumeMounts:
- name: varlog
mountPath: /var/log
readOnly: false
- name: containers
mountPath: /var/lib/docker/containers
readOnly: false
volumes:
- name: containers
hostPath:
path: /var/lib/docker/containers
- name: varlog
hostPath:
path: /var/log
K8s使用.spec.updateStrategy来指定DaemonSet的升级策略,语法如下:
updateStrategy:
type: RollingUpdate(default)/OnDelete
RollingUpdate:滚动升级,更新DS模板时,旧的Pod副本被自动删除,新的副本被自动创建
OnDelete:只有手动删除DS在一个节点上创建的副本,新的Pod副本才被创建出来