浅谈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
相关推荐
Continue_with2 小时前
docker设置代理
运维·docker·容器
彭泽布衣2 小时前
远程登录docker执行shell报错input is not a terminal问题
运维·docker·容器
霖002 小时前
FPGA通信设计十问
运维·人工智能·经验分享·vscode·fpga开发·编辑器
NUZGNAW2 小时前
VMware安装Centos 7
linux·运维·centos
筑梦之路3 小时前
linux 系统找出磁盘IO占用元凶 —— 筑梦之路
linux·运维·服务器
ezreal_pan3 小时前
docker设置镜像加速
运维·docker·容器
杰哥技术分享4 小时前
Ubuntu 22.04安装SQL Server指南
linux·运维·ubuntu·sqlserver
遇见火星4 小时前
ubuntu18.04 升级Ubuntu 20.04
linux·运维·ubuntu·系统升级
Gene_20225 小时前
【TOOL】ubuntu升级cmake版本
linux·运维·ubuntu
宇钶宇夕5 小时前
S7-200 SMART CPU 密码清除全指南:从已知密码到忘记密码的解决方法
运维·服务器·数据库·程序人生·自动化