Kubernetes 환경 자원 모니터링을 위한 Prometheus와 Grafana
Kubernetes 환경에서 애플리케이션을 운영할 때, 자원 사용량, 애플리케이션 성능 및 시스템의 전반적인 상태를 지속적으로 모니터링하는 것은 중요합니다. 모니터링을 통해 시스템 문제를 미리 감지하고 최적화를 진행하여 안정적인 서비스를 운영할 수 있습니다. 많은 기업들이 이러한 목표를 달성하기 위해 Prometheus와 Grafana를 선택합니다.
Prometheus와 Grafana 소개
Prometheus는 오픈 소스 시스템 모니터링 및 경고 도구입니다. Kubernetes와 원활하게 통합되어 Kubernetes 클러스터의 다양한 메트릭을 수집, 저장, 쿼리할 수 있으며, 알림 설정도 가능합니다. Prometheus는 다양한 데이터 소스를 지원하며, PromQL이라는 유연한 쿼리 언어를 사용하여 이 데이터를 쿼리할 수 있습니다.
Grafana는 데이터 시각화 및 분석을 위한 오픈 소스 플랫폼입니다. Prometheus에서 수집한 메트릭을 시각화하여 보다 직관적으로 시스템의 상태를 파악할 수 있게 해줍니다.
설치
kubernetes 클러스터가 설치되어 있어야하고 Kubernetes 패키지 매니저 Helm으로 설치 진행한다.
- 메트릭 서버(Metrics Server) 설치
kubectl apply -f <https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml>
- Helm 설치
# Helm 설치
curl <https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3> | bash
- Prometheus 설치
helm repo add prometheus-community <https://prometheus-community.github.io/helm-charts>
helm repo update
helm install my-prometheus prometheus-community/prometheus
- Grafana 설치
# Grafana 설치
helm repo add grafana <https://grafana.github.io/helm-charts>
helm repo update
helm install my-grafana grafana/grafana
- 대시보드 접근
kubectl port-forward deploy/my-prometheus-server 9090
kubectl port-forward deploy/my-grafana 3000
Prometheus와 Grafana를 도입함으로써, Kubernetes 클러스터의 모니터링을 강화할 수 있습니다. 이를 통해 인프라와 애플리케이션의 성능을 지속적으로 모니터링하면서 시스템의 안정성을 확보할 수 있습니다. Prometheus의 유연한 쿼리 언어와 Grafana의 강력한 시각화 기능을 활용하여, 복잡한 운영 환경에서도 효과적인 모니터링 전략을 수립할 수 있습니다.