当Kubernetes的configmap更新时,刷新daemonset pods

3
如何在更新与 Daemonsets 相关联的 configmap 时自动重启 Kubernetes pods?
根据 kubernetes 文档,当 configmap 卷挂载更新时,它会自动更新 pods。但是,我没有看到这种情况发生在 Daemonsets 上。我漏掉了什么吗?
下面是我的 configmap。
apiVersion: v1
kind: ConfigMap
metadata:
  name: fluent-bit-update
  namespace: default
  labels:
    k8s-app: fluent-bit
data:
  # Configuration files: server, input, filters and output
  # ======================================================
  fluent-bit.conf: |
    [SERVICE]
        Flush         1
        Log_Level     info
        Daemon        off
        Parsers_File  parsers.conf


    @INCLUDE input-kubernetes.conf
    @INCLUDE filter-kubernetes.conf
    @INCLUDE output-logaggregator.conf

  input-kubernetes.conf: |
    [INPUT]
        Name              tail
        Tag               kube.*
        Path              /var/log/containers/abc.log
        Parser            docker
        DB                /var/log/tail-containers-state.db
        DB.Sync           Normal
        Mem_Buf_Limit     5MB
        Skip_Long_Lines   On
        Refresh_Interval  10
        Rotate_Wait      60
        Docker_Mode      On

  filter-kubernetes.conf: |

    [FILTER]
        Name                kubernetes
        Match               kube.*
        Kube_URL            https://kubernetes.default.svc:443
        Kube_CA_File        /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        Kube_Token_File     /var/run/secrets/kubernetes.io/serviceaccount/token
        Kube_Tag_Prefix     kube.var.log.conatiners.
        Merge_Log           On
        Keep_Log            Off
        K8S-Logging.Parser  On
        K8S-Logging.Exclude Off
        Labels              On
        Annotations         On

  output-kubernetes.conf: |

    [OUTPUT]
        Name              cloudwatch
        Match             kube.*
        region            us-west-2
        log_group_name    fluent-bit-cloudwatch
        log_stream_prefix from-fluent-bit
        auto_create_group true

  parsers.conf: |

    [PARSER]
        Name         docker
        Format       json
        Time_Key     time
        Time_Format  %Y-%m-%dT%H:%M:%S.%L
        Time_Keep    On
        Decode_Field_As   escaped_utf8    log    do_next
        Decode_Field_As   json       log

    [PARSER]
        Name         docker_default
        Format       json
        Time_Key     time
        Time_Format  %Y-%m-%dT%H:%M:%S.%L
        Time_Keep    On

我的守护进程集清单文件
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: fluent-bit-update
  namespace: default
  labels:
    k8s-app: fluent-bit-logging
    version: v1
    kubernetes.io/cluster-service: "true"
spec:
  template:
    metadata:
      labels:
        k8s-app: fluent-bit-logging
        version: v1
        kubernetes.io/cluster-service: "true"
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "2020"
        prometheus.io/path: /api/v1/metrics/prometheus
    spec:
      containers:
        - name: aws-for-fluent-bit
          image: amazon/aws-for-fluent-bit:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 2020
          volumeMounts:
            - name: varlog
              mountPath: /var/log
            - name: varlibdockercontainers
              mountPath: /var/lib/docker/containers
              readOnly: true
            - name: fluent-bit-volume
              mountPath: /fluent-bit/etc/
      terminationGracePeriodSeconds: 10
      volumes:
        - name: varlog
          hostPath:
            path: /var/log
        - name: varlibdockercontainers
          hostPath:
            path: /var/lib/docker/containers
        - name: fluent-bit-volume
          configMap:
            name: fluent-bit-update
      serviceAccountName: fluent-bit
      tolerations:
        - key: node-role.kubernetes.io/master
          operator: Exists
          effect: NoSchedule
        - operator: "Exists"
          effect: "NoExecute"
        - operator: "Exists"
          effect: "NoSchedule"

当我更新configmap中的Path字段以读取另一个日志文件时,尽管我看到卷挂载被更新,但除非我删除并重新创建daemonset,否则我不会看到pod捕捉到更改。
有没有一种自动完成此操作的方法,而无需重启daemonset?我会感激您提供一些指导。谢谢。

使用Reloader是唯一的选择吗? - undefined
关于“我看不到pods正在接收更改”的意思是什么?Kubernetes只负责使用更新的配置映射来更新卷。 - undefined
2个回答

6
kubectl rollout restart  ds/<daemonset_name> -n namespace

这将进行滚动更新,并使用更新后的configMaps。


5
根据您提供的文档,Kubernetes将更新configmap(在您的情况下是fluent-bit配置),但由您的应用程序负责选择更新后的配置。通常,应用程序在启动时获取配置,但要定期更新配置,您的应用程序应支持此功能或者可以使用另一个模块(如配置更新器),当配置更改时重新启动您的应用程序(而不重新启动pod)。 对于fluent-bit,您可以参考此Github问题了解动态配置。 Prometheus已经支持此功能,例如这个

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接