如何覆盖kube-prometheus-stack helm chart中的alertmanager配置



我正在部署一个来自kube-prometheus-stackhelm图的监控堆栈,并且我正在尝试配置alertmanager,以便它具有我在Slack通道中用于警报的自定义配置。

pod中的配置是从/etc/alertmanager/config/alertmanager.yaml加载的。从pod描述中,这个文件是从一个自动生成的秘密中加载的:

...
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中?

alertmanager需要某些非默认参数来覆盖默认值,因为它似乎静默失败。错误的配置导致pod不应用配置(https://github.com/prometheus-community/helm-charts/issues/1998)。对我来说有效的方法是仔细配置alertmanager,并添加看门狗子路由和空接收器

route:
group_by: [ '...' ]
group_wait: 30s
group_interval: 10s
repeat_interval: 10s
receiver: 'user1'
routes:
- match:
alertname: Watchdog
receiver: 'null'
receivers:
- name: 'null'
- ...

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

1)从自定义alertmanager创建一个Config映射。yaml文件

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将覆盖容器中的文件。

最新更新