k8s——daemonset
daemonset
为每一个匹配的node都部署一个守护进程
# daemonset node:type=logs
daemonset 选择节点
- nadeSelector: 只调度到匹配指定的label的node上
- nodeAffinity:功能更丰富的node选择器,比如支持集合操作
- podAffinity:调度到满足条件的po所在的node上
daemonset 的实例
[root@master daemonset]# cat fluentd.yml
apiVersion: apps/v1
kind: DaemonSet # 创建daemonset 资源
metadata:
name: fluentd # 名字
spec:
selector:
matchLabels:
app: loging
template:
metadata:
labels:
app: loging
id: fluentd
name: fluentd # pod的名字
spec:
containers:
- name: fluentd-es
image: agilestacks/fluentd-elasticsearch:v1.3.0
env: # 环境变量
- name: FLUENTD_ARGS # 环境变量的key
value: -qq # 环境变量的value
volumeMounts: # 加载数据卷,避免数据丢失
- name: containers # 数据卷的名字
mountPath: /var/lib/docker/containers # 将数据卷挂载到容器内的哪个目录
- name: varlog
mountPath: /varlog
volumes: # 定义数据卷
- hostPath: # 数据卷类型,主机路径的模式,也就是与node共享目录
path: /var/lib/docker/containers # node中的共享目录
name: containers # 定义的数据卷的名称
- hostPath: # 数据卷采用的是主机目录的方式
path: /var/log
name: varlog
[root@master daemonset]#
使用标签
spec:
revisionHistoryLimit: 10
selector:
matchLabels:
app: loging
template:
metadata:
creationTimestamp: null
labels:
app: loging
id: fluentd
name: fluentd
spec:
nodeSelector:
type: microservices
# 层级关系: spec.template.spec.nodeSelector
滚动更新(不建议使用)
因为滚动更新一旦修改模版内的内容就会自动进行更新。
在一定程度上会浪费资源,所以我们一般会把更新策略换成OnDelete策略
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了