k8s控制器,daemonset

一、DaemonSet 是什么?

DaemonSet = 守护进程集 核心作用:保证集群里 每一个节点 都运行 一个 Pod

  • 不需要写 replicas(节点数 = Pod 数)
  • 新增节点 → 自动创建 Pod
  • 删除节点 → 自动删除 Pod
  • 每个节点 永远只跑一个

二、典型应用场景

  1. 节点监控node-exporter(Prometheus 采集监控)
  2. 日志收集fluentdfilebeat
  3. 网络 / 存储插件calicoceph
  4. 其他 agent:各种监控代理、安全客户端

三、完整标准 YAML

node1,node2上运行

复制代码
vim k8s-ds.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: ds
  namespace: default
  labels:
    app: ds
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.20.2
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: localtime
          mountPath: /etc/localtime
      terminationGracePeriodSeconds: 30
      volumes:
      - name: localtime
        hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai

kubectl apply -f k8s-ds.yaml

master(容忍),node1,node2上运行

复制代码
vim k8s-ds-tole.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: ds
  namespace: default
  labels:
    app: ds
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      tolerations:
      - key: node-role.kubernetes.io/control-plane #节点的污点是这个 → 必须匹配!
        operator: Exists # 存在即可,不用写value
        effect: NoSchedule # 容忍"不调度"污点
      containers:
      - name: nginx
        image: nginx:1.20.2
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: localtime
          mountPath: /etc/localtime
      terminationGracePeriodSeconds: 30
      volumes:
      - name: localtime
        hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai

kubectl apply -f k8s-ds-tole.yaml
相关推荐
Eric.Lee20214 小时前
docker 启动停止命令
运维·docker·容器
小义_9 小时前
【Kubernetes】(五) pod2
linux·云原生·容器·kubernetes
刘某的Cloud9 小时前
docker commit 封装镜像
运维·docker·容器·image
古城小栈10 小时前
Docker 下配置 Pgsql 主从复制详细步骤指南
运维·docker·容器
雨奔10 小时前
Kubernetes 对象标识详解:Name、UID、Label
云原生·容器·kubernetes
何中应11 小时前
Docker-Compose环境配置&使用
运维·docker·容器
说实话起个名字真难啊13 小时前
Docker 入门之单机常用命令总结
docker·容器·eureka
老实巴交的麻匪13 小时前
Exception异常架构设计:系统性异常处理的思维革命(05)
运维·云原生·架构
国产化创客14 小时前
RuView开源项目Docker+ESP32完整部署手册
物联网·docker·容器·开源·信息与通信·智能硬件·wifi-csi
SL-staff15 小时前
2026企业文档选型白皮书:功能、技术栈、私有化部署与采购建议
spring cloud·docker·微服务·kubernetes·开源·私有化部署·企业文档