[stable/prometheus] Load alerts and rules from configmap #9254
Comments
@jaipradeesh perhaps try
|
I just recently solved this issue for my own use. Perhaps this will help you. Or, perhaps someone with more experience will be able to offer up something better. First, I loaded all my alerts files into a directory and created a single configMap to contain all the various files with: #!/bin/bash
ALERT_NAME=prometheus-alerts
kubectl create configmap ${ALERT_NAME} --from-file alerts/ --namespace monitoring -o yaml --dry-run | kubectl apply -f - This gives me a single shell script that will update the config map as new alerts are added to that directory. Now, we need to configure Prometheus to mount that configmap and tell Prometheus where to look for alerts and rules files. I did that with the following values: # mount alerts at `/etc/config/alerts`
server:
extraConfigmapMounts:
- name: prometheus-alerts
mountPath: /etc/config/alerts
configMap: prometheus-alerts
readOnly: true
# configure Prometheus to look at `/etc/config/alerts` for alert files
serverFiles:
prometheus.yml:
rule_files:
- /etc/config/rules/*.yaml
- /etc/config/alerts/*.yaml Note: I'm using a blob-type Lastly, for bonus points, we can configure the configmapReload:
extraConfigmapMounts:
- name: prometheus-alerts
mountPath: /etc/alerts
configMap: prometheus-alerts
readOnly: true
extraVolumeDirs:
- /etc/alerts Test it by creating an alert, running the bash script to load it into the configmap, and port-forwarding 9090 from the prometheus-server pod to your localhost. The alert should be shown on the Hope this helps! |
Thanks @danieldides |
What happens when you have multiple apps, each with their own set of alerts (and each with their own helm chart). If we have a single ConfigMap, such as in @danieldides example, then each app would need to update it (ie. patch it). Helm doesn't seem to support updating pre-existing resources though (in our case the Do you guys have any suggestions in this area? |
In this video https://www.linkedin.com/learning/kubernetes-monitoring-with-prometheus/creating-alerts-in-prometheus The speaker talk about the auto-discovery of alert rules configmap. I tried it but the alert does not appear. I did not find any documentation about this special label "role: prometheus-role". |
As they mention in the video they use prometheus-operator. So this is not possible with just prometheus as installed with the prometheus chart. |
@danieldides does it work for you on latest stable version ? Cause I get a error on prometheus.yml file . |
incredibly informative ^^ |
@danieldides I took inspiration from that you did and I went one step ahead and added a sidecar container to watch for configmaps. Here is my configuration extraVolumes:
- name: prometheus-alerts
emptyDir: {} extraVolumeMounts:
- mountPath: "/etc/config/alerts"
name: "prometheus-alerts" sidecarContainers:
- name: alert-datasources
image: kiwigrid/k8s-sidecar:0.1.99
imagePullPolicy: IfNotPresent
env:
- name: METHOD
value: WATCH
- name: LABEL
value: alertmanager_datasource
- name: NAMESPACE
value: ALL
- name: FOLDER
value: "/etc/config/alerts"
- name: REQ_URL
value: http://localhost:9090/-/reload
- name: REQ_METHOD
value: POST
- name: RESOURCE
value: "configmap"
volumeMounts:
- name: prometheus-alerts
mountPath: /etc/config/alerts To anyone still wanting this functionality. |
Very good idea. Can you provide some detailed configuration? Thank you very much! |
This is not working. server: configure Prometheus to look at
|
Is this a request for help?:
Yes
Is this a BUG REPORT or FEATURE REQUEST? (choose one):
Feature req
Version of Helm and Kubernetes:
Which chart:
stable/prometheus
What happened:
How to load alerts and rules from configmap rather then polluting values.yaml file
Update the instructions please?
What you expected to happen:
How to reproduce it (as minimally and precisely as possible):
Anything else we need to know:
The text was updated successfully, but these errors were encountered: