Zum Hauptinhalt springen

Prometheus

Prometheus는 Lumie 인프라의 핵심 메트릭 수집 및 저장 시스템입니다. Kubernetes 환경에서 kube-prometheus-stack을 통해 배포되며, OpenTelemetry Collector와 통합되어 효율적인 메트릭 파이프라인을 구성합니다.

아키텍처

배포 구성

  • 네임스페이스: prometheus
  • 차트: kube-prometheus-stack v80.0.0
  • 이미지: zot.lumie-infra.com/prometheus/prometheus:v3.8.0
  • 복제본: 1개 (단일 인스턴스)

주요 구성 요소

메트릭 수집 방식

OTLP 네이티브 수신

Prometheus 3.0+의 네이티브 OTLP 수신기를 사용하여 OpenTelemetry Collector로부터 직접 메트릭을 수신합니다:

# Prometheus 설정
enableOTLPReceiver: true
enableRemoteWriteReceiver: false

Target Allocator 통합

OpenTelemetry Target Allocator가 ServiceMonitor를 읽어 스크래핑 대상을 분산 처리합니다:

# ServiceMonitor 선택기 (직접 스크래핑 비활성화)
serviceMonitorSelector:
matchLabels:
scrape-by: prometheus-only

저장 및 보존

로컬 저장

  • 보존 기간: 3일
  • 스크래핑 간격: 60초
  • 평가 간격: 60초
  • 저장소: emptyDir (영구 저장소 없음)

TSDB 설정

tsdb:
outOfOrderTimeWindow: 5m # OTel Collector의 순서 없는 샘플 허용

Thanos 통합

Sidecar 모드

Prometheus와 함께 Thanos Sidecar가 실행되어 쿼리 기능을 제공합니다:

thanos:
image: zot.lumie-infra.com/thanos/thanos:v0.37.2
# objectStorageConfig 제거 - 로컬 저장소만 사용

쿼리 엔드포인트

  • Thanos Query: http://thanos-query.thanos.svc.cluster.local:9090
  • Prometheus 직접: http://prometheus-kube-prometheus-prometheus.prometheus.svc.cluster.local:9090

메트릭 최적화

고카디널리티 메트릭 필터링

kubelet 엔드포인트에서 히스토그램 버킷 메트릭을 제거하여 메모리 사용량을 최적화합니다:

metricRelabelings:
# API 서버 히스토그램 버킷 제거 (~33k 시리즈)
- action: drop
regex: "apiserver_.*_bucket"
sourceLabels: [__name__]
# etcd 히스토그램 버킷 제거 (~18k 시리즈)
- action: drop
regex: "etcd_.*_bucket"
sourceLabels: [__name__]

비활성화된 구성 요소

메모리 절약을 위해 일부 구성 요소를 비활성화합니다:

kubeApiServer:
enabled: false # ~37k 시리즈 절약
kubeEtcd:
enabled: false # ~26k 시리즈 절약

알림 규칙

기본 규칙

kube-prometheus-stack의 기본 알림 규칙을 사용하며, 일부 규칙은 비활성화됩니다:

defaultRules:
disabled:
KubeCPUOvercommit: true
KubeMemoryOvercommit: true
PrometheusDuplicateTimestamps: true

커스텀 규칙

OOM 킬 감지를 위한 추가 규칙:

additionalPrometheusRulesMap:
oom-rules:
groups:
- name: oom.rules
rules:
- alert: ContainerOOMKilled
expr: |
increase(kube_pod_container_status_restarts_total[10m]) > 0
and on (namespace, pod, container)
kube_pod_container_status_last_terminated_reason{reason="OOMKilled"} == 1

외부 라벨

모든 메트릭에 클러스터 식별자가 추가됩니다:

externalLabels:
cluster: "mayne-cluster"

리소스 설정

컴퓨팅 리소스

resources:
requests:
cpu: 50m
memory: 800Mi
limits:
memory: 800Mi # CPU 제한 없음 (안정성 우선)

우선순위

priorityClassName: medium-priority

접근 방법

Teleport 접근

# Teleport 앱 로그인
tsh app login prometheus
tsh app config prometheus

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

포트 포워딩

# 개발용 포트 포워딩
kubectl port-forward -n prometheus svc/prometheus-kube-prometheus-prometheus 9090:9090

# 브라우저에서 http://localhost:9090 접근

쿼리 예제

기본 메트릭 쿼리

# CPU 사용률
rate(container_cpu_usage_seconds_total[5m])

# 메모리 사용률
container_memory_working_set_bytes

# 파드 재시작 횟수
increase(kube_pod_container_status_restarts_total[1h])

# 노드 CPU 사용률
100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)

애플리케이션 메트릭

# HTTP 요청 비율
rate(http_requests_total[5m])

# 에러율
rate(http_requests_total{status=~"5.."}[5m]) / rate(http_requests_total[5m])

# 응답 시간 (P95)
histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))

문제 해결

메트릭이 표시되지 않는 경우

# Prometheus 타겟 상태 확인
kubectl exec -n prometheus prometheus-kube-prometheus-prometheus-0 -- \
promtool query instant 'up'

# ServiceMonitor 확인
kubectl get servicemonitors -A -l release=prometheus

# OpenTelemetry Collector 상태 확인
kubectl get otelcol -n opentelemetry

높은 메모리 사용량

# 시리즈 수 확인
kubectl exec -n prometheus prometheus-kube-prometheus-prometheus-0 -- \
promtool query instant 'prometheus_tsdb_symbol_table_size_bytes'

# 카디널리티 확인
kubectl exec -n prometheus prometheus-kube-prometheus-prometheus-0 -- \
promtool query instant 'prometheus_tsdb_head_series'

설정 검증

# Prometheus 설정 검증
kubectl exec -n prometheus prometheus-kube-prometheus-prometheus-0 -- \
promtool check config /etc/prometheus/prometheus.yml

# 규칙 검증
kubectl exec -n prometheus prometheus-kube-prometheus-prometheus-0 -- \
promtool check rules /etc/prometheus/rules/*.yml

모니터링 대상

인프라 구성 요소

  • Kubernetes API 서버
  • kubelet (cAdvisor 포함)
  • Node Exporter
  • Kube State Metrics
  • CoreDNS

애플리케이션

  • OpenTelemetry Collector를 통한 애플리케이션 메트릭
  • 커스텀 메트릭 엔드포인트

외부 서비스

  • Blackbox Exporter를 통한 웹사이트 모니터링

보안 설정

이미지 풀 시크릿

Vault를 통해 관리되는 Zot 레지스트리 인증:

imagePullSecrets:
- name: zot-registry-credentials

RBAC

Prometheus Operator가 필요한 권한만 가지도록 제한된 RBAC 설정을 사용합니다.

관련 문서