일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 정처기
- db
- 우분투
- Ai
- mysql
- Kubernetes
- Lv 2
- 프로그래머스
- 머신러닝
- 파이썬
- 쿠버네티스
- github
- Java
- 데이터베이스
- programmers
- docker
- 자료구조
- LV 0
- 리눅스
- 코테
- 자바
- Python
- 알고리즘
- 깃
- git
- 코딩테스트
- Linux
- DevOps
- ubuntu
- 인공지능
Archives
- Today
- Total
Myo-Kyeong Tech Blog
[Kubernetes] Prometheus & Alertmanager 로 쿠버네티스 임계치 초과 시 Slack 알림 받기 본문
DevOps/Kubernetes
[Kubernetes] Prometheus & Alertmanager 로 쿠버네티스 임계치 초과 시 Slack 알림 받기
myo-kyeong 2025. 3. 19. 00:55728x90
반응형

Prometheus와 Alertmanager를 활용하여 쿠버네티스(Kubernetes) 시스템 리소스(CPU, 메모리, 디스크)가 특정 임계치를 초과했을 때 Slack (또는 Email, MS Teams 등) 으로 알람을 전송하는 방법에 대해 정리한 글입니다.
Prometheus + Alertmanager 알람 전송 흐름

- Prometheus가 메트릭을 수집 (CPU 사용률, 메모리 사용량, 디스크 사용량 등)
- PrometheusRule을 통해 특정 임계치를 초과하는 경우 알람을 발생
- Alertmanager로 알람을 전송
- Alertmanager는 AlertmanagerConfig를 참고하여 알람을 Slack (또는 Email, MS Teams 등) 으로 전송
다음과 같이 쿠버네티스에서 임계치 초과 알람을 설정하려면 두 가지 구성 요소가 필요합니다.
- PrometheusRule → 어떤 조건에서 알람을 발생시킬지 정의 (예: CPU 사용률이 80%를 넘으면 알람 발생)
- AlertmanagerConfig → 알람을 어디로, 어떻게 보낼지 설정 (Slack, Email, MS Teams 등으로 알람 전송)
PrometheusRule 설정 (알람 트리거 조건)
- 특정 임계치 초과했을 때 Prometheus가 알람 발생하도록 PrometheusRule을 설정
- 예제 : CPU 사용률이 80% 초과 -> 알람 발생
- prometheus-rule.yaml (CPU 임계치 알람 설정)
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: node-cpu-usage # 알람 규칙 이름
namespace: monitoring
spec:
groups:
- name: node_cpu_alerts
rules:
- alert: HighCPUUsage # 알람 이름 설정
expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 5m
labels:
severity: critical
annotations:
summary: "High CPU Usage on {{ $labels.instance }}"
description: "CPU usage on {{ $labels.instance }} exceeded 80% for more than 5 minutes."
- 설명
- expr : CPU 사용률이 80%를 초과하는지 확인하는 PromQL 쿼리
- for: 5m: 5분 동안 유지되면 알람 발생 ( 예 : 5분 동안 CPU 사용률이 80%를 초과하면 알람 발생 )
- labels: 알람 심각도 (critical)
- annotations: Slack 에서 보일 내용
- 설정 적용
kubectl apply -f prometheus-rule.yaml
다음과 같이 설정을 적용하면 이제 CPU 사용률이 80% 넘기면 Alertmanager로 알람을 보냅니다!
AlertmanagerConfig 설정 (Slack으로 알람 전송)
- Prometheus가 감지한 알람을 Alertmanager가 Slack으로 보낼 수 있도록 설정
- 예제 : Slack으로 알람 전송
- alertmanager-config.yaml (Slack 알람 설정)
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
name: slack-alerts # 알람 이름 설정
namespace: monitoring
spec:
route:
receiver: slack-notifications
group_by: ['alertname']
repeat_interval: 1h # 같은 알람이 1시간에 한 번만 오도록 설정
receivers:
- name: 'slack-notifications'
slackConfigs:
- send_resolved: true
channel: '#alerts' # Slack에서 알람을 받을 채널 이름 (#alerts)
apiURL:
name: slack-webhook
key: webhook-url
title: '{{ .CommonAnnotations.summary }}'
text: '{{ .CommonAnnotations.description }}'
- 설명
- repeat_interval: 1h: 같은 알람이 다시 발생해도 1시간 동안 추가 알람을 보내지 않음 (알람이 너무 자주 울리지 않도록 설정 가능)
- slackConfigs: Slack Webhook URL을 이용해 알람 전송
- send_resolved: true: 알람이 해제되었을 때도 Slack에 메시지 전송
- 설정 적용
kubectl apply -f alertmanager-config.yaml
728x90
반응형
'DevOps > Kubernetes' 카테고리의 다른 글
[Kubernetes] 쿠버네티스 OLM(Operator Lifecycle Manager) 설치 (0) | 2025.01.12 |
---|---|
[Kubernetes] 쿠버네티스에서 Secret을 다른 namespace로 복사하기 (0) | 2024.12.03 |
[Kubernetes] Metric API 오류 해결 방법 : Docker Desktop에 Metrics Server 설치 및 TLS 인증 문제 해결 (1) | 2024.08.11 |
[Kubernetes] 쿠버네티스 네트워크 통신 오브젝트 : Service 와 Ingress (2) | 2024.05.06 |
[Kubernetes] 쿠버네티스 CronJob으로 작업 스케줄링하기 (3) | 2024.03.06 |