이 글에서 다루는 것

Prometheus로 Kubernetes 클러스터 메트릭을 수집하고, Grafana 대시보드로 시각화하는 모니터링 기초를 다룹니다.

선수지식


이 단계에서 해결하려는 문제

Kubernetes 클러스터에서 Pod, Node의 CPU/메모리 사용량을 실시간으로 파악하지 못하면, 장애 대응과 리소스 최적화가 불가능합니다. Prometheus가 메트릭을 수집하고, Grafana가 이를 대시보드로 시각화합니다. 이 구조는 MLOps에서 모델 서빙 지연, 학습 리소스 모니터링의 기반이 됩니다.

실습 코드: GitHub (Monitoring)


🧭 전체 흐름 요약

① Helm 저장소 추가
② Prometheus 설치 (메트릭 수집)
③ Grafana 설치 (대시보드 시각화)
④ Web UI 접속 → Prometheus 연결 → 대시보드 불러오기

📂 디렉토리 구성

k8s-monitoring/
├── values-prometheus.yaml   # Prometheus 커스터마이징 설정
├── values-grafana.yaml      # Grafana 설정 + 비밀번호 지정
├── README.md

⚙️ [1단계] Helm 저장소 추가

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update

📦 [2단계] Prometheus 설치

기본 설치

helm install prometheus prometheus-community/prometheus
kubectl port-forward svc/prometheus-server 9090:80

접속: http://localhost:9090


NodePort 설정 (선택)

# values-prometheus.yaml
server:
  service:
    type: NodePort
    nodePort: 30091
helm install prometheus prometheus-community/prometheus -f values-prometheus.yaml

접속: http://<minikube-ip>:30091


📈 [3단계] Grafana 설치

기본 설치

helm install grafana grafana/grafana
kubectl port-forward svc/grafana 3000:80

접속: http://localhost:3000

  • ID: admin
  • PW: secret에서 추출

Grafana 접속 비밀번호 확인 (secret 추출)

kubectl get secret grafana -o jsonpath="{.data.admin-password}" | base64 -d

또는 values-grafana.yaml에서 직접 지정:

NodePort 설치 + 비밀번호 설정

# values-grafana.yaml
service:
  type: NodePort
  nodePort: 30092
adminPassword: "admin1234"
helm install grafana grafana/grafana -f values-grafana.yaml

접속: http://<minikube-ip>:30092 (ID: admin / PW: admin1234)


🧪 [4단계] Grafana에서 Prometheus 연결

  1. 좌측 톱니바퀴 > Data Sources
  2. Prometheus 선택 → URL: http://prometheus-server

📊 [5단계] 대시보드 가져오기

  1. 좌측 + 버튼 > Import
  2. Dashboard ID:
    • 315 (Kubernetes cluster monitoring)
    • 6417 (Node Exporter Full)

✅ 정리 요약

구성 요소역할
Prometheus쿠버네티스 자원 모니터링 메트릭 수집
Grafana실시간 대시보드 시각화 도구
Helm패키지 관리 (설치/업그레이드/삭제 자동화)
NodePort/port-forward웹 UI 접속 방식 선택 가능

설계 판단 (Why This Way?)

오픈소스 Prometheus+Grafana 조합으로 비용 없이 커스터마이징 가능한 모니터링을 구축하되, 프로덕션에서는 ServiceMonitor CRD 기반 Prometheus Operator 방식이 표준입니다.


다음에 읽을 글

Airflow 1단계: 로컬 환경에서 기본 DAG 실행 — Docker 기반 Airflow 환경 구성과 첫 DAG 실행