浅谈DaemonSet

1. DaemonSet 概述

  • 定义‌:DaemonSet 确保 Kubernetes 集群的每个节点上运行一个 Pod 实例。
  • 特性 ‌:
    • 每个节点上只有一个 Pod 实例。
    • 新节点加入集群时,会自动在新节点上创建 Pod。
    • 旧节点被删除时,其上的 Pod 会被回收。

2. DaemonSet 的应用场景

  • 网络插件‌:处理容器网络。
  • 存储插件‌:挂载远程存储目录,操作容器的 Volume 目录。
  • 监控和日志‌:收集节点的监控信息和日志。

3. DaemonSet 的工作原理

  • 控制器模型 ‌:
    • DaemonSet Controller 从 Etcd 获取所有节点列表。
    • 遍历节点,检查并管理 Pod。
  • nodeAffinity ‌:
    • 创建 Pod 时,DaemonSet 自动为 Pod 添加 nodeAffinity,确保 Pod 只在指定节点上启动。
  • tolerations ‌:
    • DaemonSet 为 Pod 添加 tolerations,使 Pod 能够"容忍"某些节点的"污点"(Taint),忽略调度限制。

4. DaemonSet的YAML配置示例

  • fluentd-elasticsearch示例‌:配置一个fluentd-elasticsearch镜像的Pod,用于收集Docker容器日志并转发到ElasticSearch。

    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: k8s.gcr.io/fluentd-elasticsearch:1.20
    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

5. DaemonSet 的版本管理与滚动更新

  • 版本管理 ‌:
    • 使用 ControllerRevision API 对象记录和管理 DaemonSet 的版本。
  • 滚动更新 ‌:
    • 修改 DaemonSet 的 Pod 模板触发滚动更新。
    • 使用 kubectl set image 命令更新镜像版本。
    • 示例:kubectl set image ds/fluentd-elasticsearch fluentd-elasticsearch=k8s.gcr.io/fluentd-elasticsearch:v2.2.0
  • 回滚 ‌:
    • 使用 kubectl rollout undo 命令将 DaemonSet 回滚到历史版本。
    • 示例:kubectl rollout undo daemonset fluentd-elasticsearch --to-revision=1 -n kube-system
相关推荐
HIT_Weston20 小时前
93、【Ubuntu】【Hugo】搭建私人博客:面包屑(一)
linux·运维·ubuntu
cuijiecheng201820 小时前
Linux下Beyond Compare过期
linux·运维·服务器
喵叔哟20 小时前
20.部署与运维
运维·docker·容器·.net
HIT_Weston20 小时前
92、【Ubuntu】【Hugo】搭建私人博客:侧边导航栏(六)
linux·运维·ubuntu
CodeAllen嵌入式20 小时前
Windows 11 本地安装 WSL 支持 Ubuntu 24.04 完整指南
linux·运维·ubuntu
RisunJan1 天前
Linux命令-ipcs命令(报告进程间通信(IPC)设施状态的实用工具)
linux·运维·服务器
HABuo1 天前
【Linux进程(四)】进程切换&环境变量深入剖析
linux·运维·服务器·c语言·c++·ubuntu·centos
橘颂TA1 天前
【Linux】死锁四条件的底层逻辑:从锁冲突到 STL 组件的线程安全实践(Ⅵ)
linux·运维·服务器·c++·死锁
黄焖鸡能干四碗1 天前
智能制造工业大数据应用及探索方案(PPT文件)
大数据·运维·人工智能·制造·需求分析