Skip to main content

Observability — 로깅 & 모니터링

보이지 않으면 관리할 수 없다 — 메트릭, 로그, 트레이스 3대 축


1. 관찰성 3대 축

flowchart LR
Metrics["메트릭<br/>(숫자)"]
Logs["로그<br/>(텍스트)"]
Traces["트레이스<br/>(요청 경로)"]

Metrics --> Dashboard["Grafana 대시보드"]
Logs --> Search["로그 검색"]
Traces --> Analysis["지연 분석"]
질문도구
메트릭"CPU가 얼마나 사용되고 있는가?"Prometheus + Grafana
로그"왜 에러가 발생했는가?"EFK, Loki + Grafana
트레이스"요청이 어디서 느려졌는가?"Jaeger, Tempo

2. 메트릭

2.1 Metrics Server

# kubectl top의 백엔드
kubectl top nodes
kubectl top pods -n production

kubelet의 cAdvisor에서 수집한 CPU/메모리 사용량을 제공. HPA도 Metrics Server에 의존.

2.2 Prometheus

K8s 모니터링의 사실상 표준. Pull 기반으로 타겟에서 메트릭을 수집.

flowchart LR
Targets["타겟<br/>(Pod, Node, Service)"]
Prom["Prometheus<br/>(수집 + 저장 + 쿼리)"]
Grafana_M["Grafana<br/>(시각화)"]
Alert["Alertmanager<br/>(알림)"]

Targets -->|"scrape"| Prom
Prom --> Grafana_M
Prom --> Alert
컴포넌트역할
Prometheus메트릭 수집, TSDB 저장, PromQL 쿼리
Grafana대시보드 시각화
Alertmanager알림 라우팅 (Slack, Email, PagerDuty)
kube-state-metricsK8s 오브젝트 상태(Deployment 상태, Pod 상태) 메트릭
node-exporter노드 시스템 메트릭 (DaemonSet)

설치: kube-prometheus-stack (Helm)

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install monitoring prometheus-community/kube-prometheus-stack -n monitoring

3. 로깅

3.1 기본 로깅

# Pod 로그
kubectl logs <pod-name>
kubectl logs <pod-name> -c <container-name> # 멀티 컨테이너
kubectl logs <pod-name> --previous # 이전 컨테이너 (크래시)
kubectl logs -f <pod-name> # 실시간 스트리밍

3.2 중앙 집중 로깅

스택구성특징
EFKElasticsearch + Fluentd + Kibana전통적, 무거움
ELKElasticsearch + Logstash + KibanaFluentd 대신 Logstash
Loki + GrafanaLoki(저장) + Promtail(수집) + Grafana(조회)✅ 경량, Prometheus와 통합

💡 Loki가 K8s 환경에서 대세. Prometheus + Grafana와 같은 스택에서 메트릭과 로그를 함께 볼 수 있어 운영 편의성이 높음. Elasticsearch 대비 리소스 사용량이 훨씬 적음.


4. 트레이싱

분산 시스템에서 하나의 요청이 여러 서비스를 거치는 경로를 추적.

도구특징
JaegerCNCF 졸업, 분산 트레이싱 표준
TempoGrafana Labs, Loki와 통합
OpenTelemetry메트릭+로그+트레이스 통합 표준 SDK

5. 디버깅

명령어용도
kubectl describe pod <pod>Pod 이벤트, 상태 상세
kubectl logs <pod>컨테이너 로그
kubectl exec -it <pod> -- /bin/sh컨테이너 내부 진입
kubectl port-forward svc/<svc> 8080:80로컬 포트 포워딩
kubectl get events --sort-by='.lastTimestamp'클러스터 이벤트
kubectl debug <pod> --image=busybox디버그 컨테이너 (ephemeral)

다음 글

→ #10 Cluster Administration