You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kubernetes DaemonSet修改注解后无法自动重启问题咨询

解决DaemonSet随ConfigMap更新自动重启的问题

核心原因

DaemonSet的滚动更新触发逻辑只关注其spec.template(Pod模板)的变更,DaemonSet元数据层面的注解更新不会被控制器识别为需要重建Pod的信号——这和Deployment的逻辑一致,你之前修改Deployment元数据注解没触发重启也是同样原因,只有Pod模板的内容变化才会触发滚动更新。

正确实现方式

把基于ConfigMap内容的SHA256校验值放到DaemonSet的spec.template.metadata.annotations里,而不是DaemonSet自身的metadata注解:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: your-daemonset-name
spec:
  selector:
    matchLabels:
      app: your-app-label
  template:
    metadata:
      annotations:
        # 这里注入ConfigMap内容的SHA256值
        config.hash.sha256: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
      labels:
        app: your-app-label
    spec:
      containers:
      - name: your-container
        image: your-image:tag
        volumeMounts:
        - name: config-volume
          mountPath: /path/to/config
      volumes:
      - name: config-volume
        configMap:
          name: your-configmap-name

验证逻辑

当ConfigMap内容变化时,SHA256值会自动更新,导致DaemonSet的Pod模板注解变更,此时DaemonSet控制器会立即触发滚动更新,逐个重建Pod以加载新的ConfigMap配置。

手动测试方法

如果要快速验证逻辑,可直接编辑DaemonSet的Pod模板注解:

kubectl edit daemonset your-daemonset-name

找到spec.template.metadata.annotations并修改任意值,保存后就能看到DaemonSet开始自动重建Pod。

内容的提问来源于stack exchange,提问作者ConscriptMR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 14:56:03