【问题标题】:How to overwrite alertmanager configuration in kube-prometheus-stack helm chart如何覆盖 kube-prometheus-stack helm chart 中的 alertmanager 配置
【发布时间】:2022-08-11 21:18:35
【问题描述】:

我正在从kube-prometheus-stack helm 图表部署一个监视堆栈,并且我正在尝试配置 alertmanager 以便它具有我在 Slack 通道中发出警报的自定义配置。

pod 中的配置是从/etc/alertmanager/config/alertmanager.yaml 加载的。 从 pod 描述中,该文件是从自动生成的 secret 中加载的:

...
  volumeMounts:
   - mountPath: /etc/alertmanager/config
     name: config-volume
...
volumes:
  - name: config-volume
    secret:
      defaultMode: 420
      secretName: alertmanager-prometheus-community-kube-alertmanager-generated

如果我检查秘密,它包含在alertmanager.config 的默认值中找到的默认配置,我打算覆盖它。

如果我将以下配置传递给 alertmanager 以重新安装图表,它不会创建 alertmanager pod:

alertmanager:
  config:
    global:
      resolve_timeout: 5m
    route:
      group_by: [\'job\', \'alertname\', \'priority\']
      group_wait: 10s
      group_interval: 1m
      routes:
      - match:
          alertname: Watchdog
        receiver: \'null\'
      - receiver: \'slack-notifications\'
        continue: true
    receivers:
    - name: \'slack-notifications\'
      slack-configs:
      - slack_api_url: <url here>
        title: \'{{ .Status }} ({{ .Alerts.Firing | len }}): {{ .GroupLabels.SortedPairs.Values | join \" \" }}\'
        text: \'<!channel> {{ .CommonAnnotations.summary }}\'
        channel: \'#mychannel\'

首先,如果我没有在values.yaml 中传递任何配置,则成功创建了alertmanager pod。

如何正确覆盖 alertmanager 的配置,以便将带有我的自定义配置的正确文件安装到 /etc/alertmanger/config/alertmanager.yaml 中?

    标签: kubernetes kubernetes-helm prometheus-alertmanager kube-prometheus-stack


    【解决方案1】:

    也许以下步骤可以解决您的问题

    1) 从自定义的 alertmanager.yaml 文件创建一个 Config map

    kubectl create configmap <name_of_the_configmap> --from-file=<path_and_name_of_thefile>
    

    2) 将 Configmap 作为卷挂载到容器中。

    ...
      volumeMounts:
       - mountPath: /etc/alertmanager/config
         name: config-volume
      volumes:
        - name: config-volume
          configMap:
            # Provide the name of the ConfigMap containing the files you want
            # to add to the container
            name: <ConfigMap_Name_Created>
    

    3) 挂载 configmap 将覆盖容器内的文件。

    【讨论】:

      【解决方案2】:

      alertmanager 需要某些非默认参数来覆盖默认值,因为它似乎在静默中失败。文档指出“括号表示参数是可选的。”,这意味着您自己的配置应至少包含以下键

      templates:
        [ - <filepath> ... ]
      route: <route>
      receivers:
        - <receiver> ...
      inhibit_rules:
        [ - <inhibit_rule> ... ]
      mute_time_intervals:
        [ - <mute_time_interval> ... ] 
      time_intervals:
        [ - <time_interval> ... ]
      

      配置见https://prometheus.io/docs/alerting/latest/configuration/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-09
        • 2021-06-26
        • 1970-01-01
        • 1970-01-01
        • 2021-02-12
        • 2021-06-04
        • 2021-06-13
        • 2021-07-13
        相关资源
        最近更新 更多