1. apiVersion: apps/v1 # 指定api版本,此值必须在kubectl api-versions中
    2. kind: DaemonSet # 指定创建资源的角色/类型
    3. metadata: # 资源的元数据/属性
    4. name: fluentd-elasticsearch # 资源的名字,在同一个namespace中必须唯一
    5. namespace: default # 部署在哪个namespace中
    6. labels: # 设定资源的标签
    7. k8s-app: fluentd-logging
    8. spec: # 资源规范字段
    9. selector: # 选择器
    10. matchLabels: # 匹配标签
    11. name: fluentd-elasticsearch
    12. template: # 模版
    13. metadata: # 资源的元数据/属性
    14. labels: # 设定资源的标签
    15. name: fluentd-elasticsearch
    16. spec: # 资源规范字段
    17. tolerations:
    18. # 允许在master节点运行
    19. - key: node-role.kubernetes.io/master
    20. effect: NoSchedule
    21. containers:
    22. - name: fluentd-elasticsearch # 容器的名字
    23. image: fluentd:v2.5.2 # 容器使用的镜像地址
    24. resources: # 资源管理
    25. limits: # 最大使用
    26. cpu: 1 # CPU,1核心 = 1000m
    27. memory: 200Mi # 内存,1G = 1024Mi
    28. requests: # 容器运行时,最低资源需求,也就是说最少需要多少资源容器才能正常运行
    29. cpu: 100m
    30. memory: 200Mi
    31. volumeMounts:
    32. - name: varlog # 挂载设备的名字,与volumes[*].name 需要对应
    33. mountPath: /var/log # 挂载到容器的某个路径下
    34. - name: varlibdockercontainers
    35. mountPath: /var/lib/docker/containers
    36. readOnly: true # 是否只读
    37. # 优雅关闭应用,时间设置。超过该时间会强制关闭【可选项】,默认30秒
    38. terminationGracePeriodSeconds: 30
    39. volumes: #定义一组挂载设备
    40. - name: varlog # 挂载的设备名
    41. hostPath:
    42. path: /var/log #挂载设备类型为hostPath,路径为宿主机下的/opt,这里设备类型支持很多种
    43. - name: varlibdockercontainers
    44. hostPath:
    45. path: /var/lib/docker/containers