본문으로 건너뛰기

Alertmanager

Alertmanager는 Lumie 인프라의 중앙 알림 관리 시스템으로, Prometheus에서 발생하는 알림을 수신하여 적절한 채널로 라우팅하고 중복 제거, 그룹화, 억제 등의 기능을 제공합니다.

아키텍처

배포 구성

  • 네임스페이스: alertmanager
  • 차트: alertmanager v1.30.0
  • 이미지: zot.lumie-infra.com/prometheus/alertmanager:v0.30.0
  • 복제본: 1개
  • 저장소: emptyDir (알림 상태는 임시 저장)

알림 파이프라인

설정 구성

SMTP 설정

iCloud 메일 서버를 통한 이메일 알림:

global:
smtp_smarthost: "smtp.mail.me.com:587"
smtp_from: "bluemayne0213@icloud.com"
smtp_auth_username: "bluemayne0213@icloud.com"
smtp_auth_password: "{{ .Secrets.SMTP_PASSWORD }}"
smtp_require_tls: true

라우팅 규칙

알림의 심각도와 유형에 따른 라우팅:

route:
group_by: ["alertname", "cluster", "service"]
group_wait: 30s
group_interval: 5m
repeat_interval: 4h
receiver: "email"
routes:
# Watchdog 알림 무시
- match:
alertname: Watchdog
receiver: "null"
# Critical 알림 - 빠른 처리
- match:
severity: critical
receiver: "email"
group_wait: 10s
repeat_interval: 1h
# Warning 알림 - 일반 처리
- match:
severity: warning
receiver: "email"
group_wait: 1m
repeat_interval: 4h

수신자 설정

receivers:
- name: "email"
email_configs:
- to: "bluemayne0213@icloud.com"
send_resolved: true
headers:
subject: "[{{ .Status | toUpper }}] {{ .CommonLabels.alertname }}"
- name: "null" # 무시할 알림용

억제 규칙

중복 알림 방지:

inhibit_rules:
- source_match:
severity: "critical"
target_match:
severity: "warning"
equal: ["alertname", "cluster", "service"]

Karma UI

개요

Karma는 Alertmanager의 웹 UI로, 현재 활성 알림을 시각적으로 관리할 수 있습니다.

배포 설정

# Karma 설정
image:
repository: zot.lumie-infra.com/prymitive/karma
tag: v0.122

env:
- name: ALERTMANAGER_URI
value: "http://alertmanager.alertmanager.svc.cluster.local:9093"

기능

  • 알림 대시보드: 현재 활성 알림 목록
  • 필터링: 라벨, 상태별 필터링
  • 그룹화: 알림 그룹별 표시
  • 음소거: 임시 알림 음소거

리소스 설정

Alertmanager

resources:
requests:
cpu: 15m
memory: 100Mi
limits:
memory: 100Mi # CPU 제한 없음

Karma

resources:
requests:
cpu: 10m
memory: 32Mi
limits:
memory: 32Mi

보안 설정

Vault 통합

SMTP 인증 정보는 Vault에서 관리됩니다:

vaultStaticSecrets:
# SMTP 인증 정보
- name: alertmanager-smtp-vss
path: observability/alertmanager
destination:
name: alertmanager-smtp
transformation:
templates:
smtp_auth_password: "{{ .Secrets.SMTP_PASSWORD }}"

# Alertmanager 설정
- name: alertmanager-config-vss
path: observability/alertmanager
destination:
name: alertmanager-config

네트워크 보안

  • 외부 인그레스 비활성화
  • Teleport를 통한 안전한 접근
  • 클러스터 내부 통신만 허용

접근 방법

Teleport 접근

# Alertmanager 접근
tsh app login alertmanager
tsh app config alertmanager

# 브라우저에서 접근
open $(tsh app config alertmanager --format=uri)

# Karma UI 접근
tsh app login karma
open $(tsh app config karma --format=uri)

포트 포워딩 (개발용)

# Alertmanager
kubectl port-forward -n alertmanager svc/alertmanager 9093:9093

# Karma
kubectl port-forward -n alertmanager svc/karma 8080:8080

알림 관리

음소거 (Silence)

특정 알림을 임시로 음소거할 수 있습니다:

# API를 통한 음소거 생성
curl -X POST http://alertmanager.alertmanager.svc.cluster.local:9093/api/v1/silences \
-H "Content-Type: application/json" \
-d '{
"matchers": [
{
"name": "alertname",
"value": "HighMemoryUsage",
"isRegex": false
}
],
"startsAt": "2024-01-01T00:00:00Z",
"endsAt": "2024-01-01T01:00:00Z",
"createdBy": "admin",
"comment": "Maintenance window"
}'

알림 상태 확인

# 현재 활성 알림 조회
curl -s http://alertmanager.alertmanager.svc.cluster.local:9093/api/v1/alerts

# 음소거 목록 조회
curl -s http://alertmanager.alertmanager.svc.cluster.local:9093/api/v1/silences

알림 규칙 예제

인프라 알림

# Prometheus에서 정의되는 알림 규칙 예제
groups:
- name: infrastructure
rules:
- alert: HighCPUUsage
expr: 100 - (avg by(instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 5m
labels:
severity: warning
annotations:
summary: "High CPU usage on {{ $labels.instance }}"
description: "CPU usage is above 80% for more than 5 minutes"

- alert: HighMemoryUsage
expr: (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100 > 90
for: 5m
labels:
severity: critical
annotations:
summary: "High memory usage on {{ $labels.instance }}"
description: "Memory usage is above 90% for more than 5 minutes"

애플리케이션 알림

groups:
- name: applications
rules:
- alert: HighErrorRate
expr: rate(http_requests_total{status=~"5.."}[5m]) / rate(http_requests_total[5m]) * 100 > 5
for: 2m
labels:
severity: critical
annotations:
summary: "High error rate in {{ $labels.service }}"
description: "Error rate is above 5% for more than 2 minutes"

- alert: SlowResponse
expr: histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m])) > 1
for: 5m
labels:
severity: warning
annotations:
summary: "Slow response time in {{ $labels.service }}"
description: "95th percentile response time is above 1 second"

문제 해결

알림이 전송되지 않는 경우

# Alertmanager 로그 확인
kubectl logs -n alertmanager deployment/alertmanager

# SMTP 설정 확인
kubectl get secret -n alertmanager alertmanager-config -o yaml

# 설정 파일 검증
kubectl exec -n alertmanager deployment/alertmanager -- \
amtool config show --config.file=/etc/alertmanager/alertmanager.yml

중복 알림 문제

# 억제 규칙 확인
kubectl exec -n alertmanager deployment/alertmanager -- \
amtool config show --config.file=/etc/alertmanager/alertmanager.yml | grep -A 10 inhibit_rules

# 현재 억제된 알림 확인
curl -s http://alertmanager.alertmanager.svc.cluster.local:9093/api/v1/alerts | \
jq '.data[] | select(.status.inhibitedBy | length > 0)'

설정 변경 적용

# 설정 리로드
kubectl exec -n alertmanager deployment/alertmanager -- \
kill -HUP 1

# 또는 파드 재시작
kubectl rollout restart -n alertmanager deployment/alertmanager

모니터링

Alertmanager 메트릭

Alertmanager 자체도 모니터링됩니다:

# 처리된 알림 수
alertmanager_notifications_total

# 실패한 알림 수
alertmanager_notifications_failed_total

# 활성 알림 수
alertmanager_alerts

# 음소거 수
alertmanager_silences

ServiceMonitor

# common-values.yaml에서 정의
serviceMonitor:
enabled: true
name: alertmanager
labels:
release: prometheus
endpoints:
- port: http
path: /metrics
interval: 60s

알림 모범 사례

알림 설계 원칙

  1. 실행 가능한 알림: 대응 방법이 명확한 알림만 생성
  2. 적절한 임계값: 너무 민감하거나 둔감하지 않게 설정
  3. 명확한 메시지: 문제와 해결 방법을 명시
  4. 심각도 분류: Critical, Warning으로 적절히 분류

라우팅 전략

# 시간대별 라우팅 (예제)
routes:
- match:
severity: critical
receiver: "oncall"
active_time_intervals:
- business_hours
- match:
severity: warning
receiver: "email"
active_time_intervals:
- business_hours

템플릿 활용

# 커스텀 이메일 템플릿
templates:
- '/etc/alertmanager/templates/*.tmpl'

receivers:
- name: "email"
email_configs:
- to: "admin@example.com"
subject: '{{ template "email.subject" . }}'
body: '{{ template "email.body" . }}'

관련 문서