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策略

posted on 2024-05-22 17:25  代码你敲我不敲  阅读(47)  评论(0)    收藏  举报

导航

返回顶端