티스토리 뷰
쿠버네티스 실습: SLA 기반 알림 시스템 구축 (Prometheus Alertmanager + Slack 연동)
octo54 2025. 10. 14. 11:05쿠버네티스 실습: SLA 기반 알림 시스템 구축 (Prometheus Alertmanager + Slack 연동)
앞선 글에서는 Prometheus + Grafana + Kiali + Jaeger를 이용해 완전한 Observability(관찰성) 환경을 구축했습니다.
이번 글에서는 관찰성 체계의 마지막 단계인 Alerting(경보 시스템) 을 구성합니다.
즉, 시스템이 스스로 이상 상태를 감지하고 Slack 등 외부 채널로 알림을 전송하는 구조를 만듭니다.
1) Alerting의 필요성
모니터링만으로는 부족합니다.
문제가 생겼을 때 관리자가 직접 확인해야만 인지한다면, 이미 장애는 서비스에 영향을 주고 있습니다.
Alerting 시스템은 다음을 자동화합니다.
- SLA 기준에 따라 CPU, 메모리, 에러율, 응답시간을 실시간 감시
- 특정 임계값 초과 시 즉시 Slack/PagerDuty 등으로 자동 알림 전송
- 자동화된 대응(예: HPA 트리거, 롤백 스크립트 호출 등)도 가능
2) Prometheus Alertmanager 설치
Prometheus에는 기본적으로 Alertmanager가 포함되어 있습니다.
만약 별도 설치를 원한다면 Helm Chart로 간단히 구성할 수 있습니다.
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack -n monitoring --create-namespace
설치 확인:
kubectl get pods -n monitoring
출력 예시:
NAME READY STATUS AGE
alertmanager-kube-prometheus-stack-0 2/2 Running 2m
prometheus-kube-prometheus-stack-0 2/2 Running 2m
grafana-xxxxxx 1/1 Running 2m
3) Alert 규칙 정의
Alert 규칙은 Prometheus 서버가 감시할 조건을 명시한 YAML 파일입니다.
alert-rules.yaml
groups:
- name: instance-alerts
rules:
- alert: HighCPUUsage
expr: avg(rate(container_cpu_usage_seconds_total[2m])) * 100 > 80
for: 1m
labels:
severity: critical
annotations:
summary: "CPU 사용률 80% 초과"
description: "Pod {{ $labels.pod }} 의 CPU 사용률이 80%를 초과했습니다."
- alert: HighMemoryUsage
expr: container_memory_usage_bytes > 800000000
for: 2m
labels:
severity: warning
annotations:
summary: "메모리 사용량 초과"
description: "Pod {{ $labels.pod }} 의 메모리 사용량이 임계값을 초과했습니다."
적용:
kubectl create configmap prometheus-alert-rules --from-file=alert-rules.yaml -n monitoring
kubectl label configmap prometheus-alert-rules prometheus=kube-prometheus-stack-rulefiles -n monitoring
4) Alertmanager 설정 (Slack Webhook 연동)
4-1. Slack Webhook 생성
- Slack 워크스페이스 → “앱 관리” → Incoming Webhooks 추가
- 알림 받을 채널 선택 (예: #devops-alert)
- 발급된 Webhook URL 복사
4-2. Alertmanager Config 적용
alertmanager-config.yaml
global:
resolve_timeout: 5m
route:
receiver: 'slack-notifications'
group_wait: 10s
group_interval: 1m
repeat_interval: 3h
receivers:
- name: 'slack-notifications'
slack_configs:
- api_url: 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXX'
channel: '#devops-alert'
send_resolved: true
title: '[K8S ALERT] {{ .CommonAnnotations.summary }}'
text: "{{ .CommonAnnotations.description }}"
적용:
kubectl create secret generic alertmanager-kube-prometheus-stack --from-file=alertmanager.yaml=alertmanager-config.yaml -n monitoring --dry-run=client -o yaml | kubectl apply -f -
5) 테스트 — CPU 부하 생성
테스트용 Pod 생성:
kubectl run load-generator --image=busybox -- /bin/sh -c "while true; do dd if=/dev/zero of=/dev/null; done"
1~2분 내 Slack 알림 예시:
[K8S ALERT] CPU 사용률 80% 초과
Pod load-generator 의 CPU 사용률이 80%를 초과했습니다.
6) Grafana에서 Alert 시각화
Grafana는 Prometheus와 통합되어 알람 히스토리를 시각화할 수 있습니다.
- Alerting → Alert Rules → Import
- alert-rules.yaml을 불러와 조건 시각화
- Slack 연동 상태 및 Trigger 확인 가능
7) SLA 기반 알람 설계 팁
항목 권장 기준 설명
| CPU 사용률 | 80% 이상 지속 1분 | 과도한 부하 감지 |
| Memory 사용량 | 90% 이상 2분 지속 | OOMKill 방지 |
| Pod 재시작 횟수 | 5회 이상/10분 | CrashLoopBackOff 조기 감지 |
| 응답 시간 | 1초 초과 3회 이상 | API 병목 감지 |
| 에러율 | 5% 초과 | 배포 문제 조기 탐지 |
8) 정리
- Prometheus Alertmanager로 쿠버네티스 상태를 실시간 감시
- Slack Webhook 연동으로 운영팀이 즉시 인지
- SLA 기준으로 알람을 자동화하면, 사후 대응에서 사전 대응으로 전환 가능
- Grafana를 통해 알람 트렌드와 히스토리까지 분석 가능
다음 글에서는 쿠버네티스 클러스터 백업/복구 전략 (Velero 사용) 을 다뤄,
예상치 못한 장애나 노드 손실 상황에서도 서비스 데이터를 복원하는 방법을 실습하겠습니다.
쿠버네티스,Prometheus,Alertmanager,Slack연동,알람시스템,SLA,DevOps,관찰성,모니터링자동화,K8s실습
🔍 보강할 부분 & 팁
1. kube-prometheus-stack와 Alertmanager 설정 방식
- 많은 쿠버네티스 모니터링 실습에서는 kube-prometheus-stack Helm Chart를 사용하여 Prometheus + Alertmanager 을 같이 배포합니다. 이 경우 Alertmanager 설정을 Helm values로 관리하는 방식을 문서에 포함하는 게 좋습니다.
- 예를 들어, Slack Webhook URL, routing, receiver 설정 등을 values.yaml에 포함시키는 방식이 일반적입니다.
- Reddit 사용자 사례에서도, alertmanager.config 블록을 values에 넣고 Slack 설정을 하는 방식이 자주 쓰이고 있음이 언급되어 있습니다. (Reddit)
2. 알림 규칙(Alerts) 정의 & PrometheusRule 리소스
- 단순 configmap 방식뿐 아니라, Prometheus Operator를 쓴다면 PrometheusRule 리소스를 사용해서 알림 규칙을 정의하는 게 표준 방식입니다.
- DigitalOcean 튜토리얼에서도 additionalPrometheusRules 섹션을 사용해 알림 규칙을 추가하는 방법을 설명하고 있습니다. (DigitalOcean)
- 이렇게 하면 Helm upgrade 시 규칙이 자연스럽게 배포/관리되기 쉬워요.
3. Alertmanager 설정 파일 유효성 체크 & reload
- Alertmanager는 설정 파일이 유효하지 않으면 로드하지 않고 오류 로그를 남깁니다. (Prometheus)
- 변경을 적용하려면 Alertmanager에 /-/reload API 엔드포인트를 호출하거나 프로세스에 SIGHUP을 보내야 합니다. (Prometheus)
- 문서에 이 점을 명시해두면 “설정 바꿨는데 알림 안 온다”는 사용자 혼란을 줄일 수 있어요.
4. Slack Webhook 구성 주의사항 & 템플릿
- Slack Webhook URL이나 채널 이름에서 실수가 자주 발생하므로, 예제 설정에서 api_url을 secret 형태로 참조하는 방식을 같이 제시하는 게 좋습니다 (즉 URL을 values.yaml에 하드코딩하는 방식보다 보안적으로 낫습니다).
- 템플릿 문법 (Go 템플릿) 을 이용해 alert summary, description, labels 등을 메시에 포함시키는 예시도 함께 제공하면 좋습니다. Prometheus 공식 문서에 여러 알림 템플릿 예시가 있음. (Prometheus)
5. 디버깅 & 문제 해결 팁
- Slack 알림이 안 오는 경우, 먼저 Alertmanager 로그를 보고 에러 메시지를 확인하라고 안내
- routes, receivers 설정이 잘못되어 알림이 필터링되는 경우가 많다는 주의
- Prometheus → Alertmanager 간 통신이 정상인지 (Alert이 Alertmanager로 넘어가는지) 점검
- Helm values 설정이 올바르게 반영되지 않은 경우가 자주 있음 — helm upgrade --recreate-pods 또는 helm diff 등을 활용하라는 팁
✅ 수정된 예시 내용 (보강된 형태)
아래는 글의 일부를 보강한 예시입니다:
# values.yaml 예시 (kube-prometheus-stack 사용 시)
alertmanager:
config:
global:
resolve_timeout: 5m
route:
receiver: slack-notifications
group_wait: 10s
group_interval: 1m
repeat_interval: 3h
receivers:
- name: slack-notifications
slack_configs:
- api_url:
valueFrom:
secretKeyRef:
name: slack-webhook-secret
key: webhook-url
channel: "#devops-alert"
send_resolved: true
title: "[K8S ALERT] {{ .CommonAnnotations.summary }}"
text: "{{ .CommonAnnotations.description }}"
# Slack Webhook Secret 예시
apiVersion: v1
kind: Secret
metadata:
name: slack-webhook-secret
type: Opaque
stringData:
webhook-url: "https://hooks.slack.com/services/XXX/YYY/ZZZ"
# PrometheusRule 리소스로 알림 규칙 정의 예
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: k8s-alerts
namespace: monitoring
spec:
groups:
- name: k8s-resources
rules:
- alert: HighCPUUsage
expr: avg(rate(container_cpu_usage_seconds_total{namespace="default"}[2m])) * 100 > 80
for: 1m
labels:
severity: critical
annotations:
summary: "CPU usage high (> 80%)"
description: "Namespace default에서 CPU 사용률이 높습니다"
'project > 맥미니로 시작하는 쿠버네티스' 카테고리의 다른 글
| 쿠버네티스 실습: GitOps 기반 배포 자동화 (Argo CD 완전 가이드) (0) | 2025.10.16 |
|---|---|
| 쿠버네티스 실습: Velero로 클러스터 백업 및 복구 자동화하기 (0) | 2025.10.15 |
| 쿠버네티스 실습: Prometheus + Grafana + Kiali + Jaeger로 완전한 Observability 구축하기 (0) | 2025.10.13 |
| 쿠버네티스 실습: Istio로 서비스 메시(Service Mesh) 구축하기 (0) | 2025.10.10 |
| 쿠버네티스 실습: 운영 환경 트러블슈팅 사례 정리 (0) | 2025.09.18 |
- Total
- Today
- Yesterday
- 백엔드개발
- ai철학
- kotlin
- fastapi
- 생성형AI
- seo 최적화 10개
- 딥러닝
- Prisma
- Python
- Docker
- 웹개발
- rag
- nextJS
- JAX
- LangChain
- PostgreSQL
- Express
- REACT
- llm
- DevOps
- Next.js
- JWT
- flax
- NestJS
- 개발블로그
- node.js
- Redis
- SEO최적화
- 쿠버네티스
- CI/CD
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 |

