prometheus operator에서의 alertmanager 구성
alertmanager는 이 alertmanager configuration파일에 따라 구동된다.
kubernetes의 prometheus operator에서 alertmanager를 구동하기 위해
alertmanager configuration을 제공하는 법은 아래와 같이 2가지방식이 있다.
1.alertmanager configuration파일을 secret을 통해 관리
2.AlertmanagerConfig라는 custom resource를 생성하고 Alertmanager 리소스(역시 custom resource)가 참조하도록 설정
*alertmanagerConfig 리소스 예시
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
name: config-example
labels:
alertmanagerConfig: example
spec:
route:
groupBy: ['job']
groupWait: 30s
groupInterval: 5m
repeatInterval: 12h
receiver: 'webhook'
receivers:
- name: 'webhook'
webhookConfigs:
- url: 'http://example.com/'
2-1. spec.alertmanagerConfiguration에 alertmanagerConfig 리소스 명시해서 사용
apiVersion: monitoring.coreos.com/v1
kind: Alertmanager
metadata:
name: example
namespace: default
spec:
replicas: 3
alertmanagerConfiguration:
name: config-example
2-2. spec.alertmanagerConfigSelector나 spec.alertmanagerConfigNamespaceSelector를 활용하여 여러 alertmanagerConfig를 merge해서 사용
apiVersion: monitoring.coreos.com/v1
kind: Alertmanager
metadata:
name: example
spec:
replicas: 3
alertmanagerConfigSelector:
matchLabels:
alertmanagerConfig: example
현재 나는 prometheus operator를 bitnami helm차트로 배포하고 있다. 때문에, values.yaml의 아래 필드들을 고려하면 될듯하다.
## @param alertmanager.configNamespaceSelector Namespaces to be selected for AlertmanagerConfig discovery. If nil, only check own namespace. This defaults to {}
##
configNamespaceSelector: {}
## @param alertmanager.configSelector AlertmanagerConfigs to be selected for to merge and configure Alertmanager with. This defaults to {}
##
configSelector: {}
## @param alertmanager.configuration EXPERIMENTAL: alertmanagerConfiguration specifies the global Alertmanager configuration. If defined, it takes precedence over the `configSecret` field. This field may change in future releases. The specified global alertmanager config will not force add a namespace label in routes and inhibitRules
##
configuration: {}
그러나 테스트해보니, 이 alertmanagerConfig 리소스를 활용하는 방식자체가 나온지 얼마안되었고, 이 리소스에서 지원안되는 Config 옵션들이 있어서 아직은 사용하기 이른것같다.
그냥 alertmanager.config 필드에 config를 입력해서, secret으로 생성하고, config-reloader(sidecar)를 통해 갱신하는게 나을것같다.
config:
global:
resolve_timeout: 5m
route:
group_by: ['job']
group_wait: 30s
group_interval: 5m
repeat_interval: 12h
receiver: 'null'
routes:
- match:
alertname: Watchdog
receiver: 'null'
receivers:
- name: 'null'
참고:
prometheus와 alertmanager의 configration.yaml파일은 각각 별개 secret으로 생성된다.
이 시크릿을 volumemount로 각 pod에서 file로 동기화해서 사용하는데, config를 변경하면 , config-reloader가 sidecar로 구성되어있어 갱신시켜준다.
alertmanager.externalConfig: true로 설정하면 secret이 생성되지 않으니 주의.
'k8s 및 인프라 > prometheus' 카테고리의 다른 글
prometheus operator (0) | 2024.03.16 |
---|---|
grafana metric 수집이슈 (0) | 2024.03.15 |
prometheus operator (0) | 2024.03.15 |