Example AlertmanagerConfig
This example demonstrates a simple route and a webhook receiver. Save it as a YAML file when creating the CRD.route, grouping settings, and one or more receivers. When deployed as a Kubernetes CRD, the AlertmanagerConfig will only be registered with an Alertmanager instance if that Alertmanager is configured to select it (selectors explained below).
Alertmanager selector settings you must know
The kube-prometheus-stack (and other Prometheus Operator installs) exposes two selector properties in the Alertmanager CR:alertmanagerConfigSelector— controls which AlertmanagerConfig objects in the same namespace are selected.alertmanagerConfigNamespaceSelector— controls which namespaces’ AlertmanagerConfig objects are selectable.
alertmanagerConfigSelector matches the labels you add to your AlertmanagerConfig resources.
Key differences: Alertmanager YAML vs AlertmanagerConfig CRD
There are two important differences between a standalonealertmanager.yml and the AlertmanagerConfig CRD:
Examples for matcher and field naming differences:
Standalone Alertmanager YAML (snake_case + simple matchers):
When converting an existing Alertmanager
alertmanager.yml to an AlertmanagerConfig CRD, convert snake_case fields to camelCase and convert simple label matchers into matchers objects with name and value.Enable AlertmanagerConfig discovery in the Helm chart
Follow these steps to configure the kube-prometheus-stack Helm chart so Alertmanager automatically discovers AlertmanagerConfig resources.- Export the chart’s default values:
- Edit
values.yamland add analertmanagerConfigSelectorso it matches the label you will use on your AlertmanagerConfig resources. For example, to matchresource: prometheus:
alertmanager:), place the selector under the appropriate key according to that chart’s values structure.
- Upgrade the release with the modified values file:
- Verify the Alertmanager CR now contains the selector you configured:
Create and apply an AlertmanagerConfig
Create a file namedalert.yaml containing the AlertmanagerConfig example. Ensure the metadata.labels include the label the Alertmanager will select (in the example above, resource: prometheus):
If you receive an error that the resource type does not exist, ensure the Prometheus Operator CRDs (including
alertmanagerconfigs.monitoring.coreos.com) are installed in your cluster.Verify Alertmanager picked up the config
Port-forward the Alertmanager service and open the UI to confirm the config was registered:Troubleshooting tips
- If your AlertmanagerConfig does not appear in Alertmanager:
- Confirm the Alertmanager’s
alertmanagerConfigSelectormatches the label on your AlertmanagerConfig. - Confirm the namespace of the AlertmanagerConfig is selected by
alertmanagerConfigNamespaceSelectorif set. - Confirm Prometheus Operator CRDs are installed and up to date.
- Confirm the Alertmanager’s
- Use
kubectl describeon the Alertmanager and AlertmanagerConfig resources to see events and errors. - Check Alertmanager logs (via Pod logs) for registration errors.
Links and references
- kube-prometheus-stack Helm chart: https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack
- Prometheus Operator / AlertmanagerConfig CRD docs: https://github.com/prometheus-operator/prometheus-operator
- Alertmanager documentation: https://prometheus.io/docs/alerting/latest/alertmanager/
- Helm documentation: https://helm.sh/docs/
- Kubernetes documentation: https://kubernetes.io/docs/