본문 바로가기

Kubernetes

Prometheus-stack으로 Grafana까지 쉽게 설치하기

반응형

Architecture

 

1. Helm 설치

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

2. Prometheus-stack (Grafana) 설치

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

2-1. 구성요소

1. Prometheus: Prometheus는 오픈 소스 모니터링 및 경고 도구로, 시스템 및 서비스의 메트릭을 수집하고 저장합니다. 설정된 주기로 대상 시스템에 HTTP 요청을 보내어 메트릭을 수집하며, 수집한 데이터를 내부 데이터베이스에 저장합니다. Prometheus는 강력한 쿼리 언어를 제공하여 데이터를 분석하고 시각화할 수 있습니다.


2. Grafana: Grafana는 데이터 시각화 및 대시보드 도구로, Prometheus에서 수집한 메트릭 데이터를 시각적으로 표시하고 대시보드를 생성할 수 있습니다. Grafana는 다양한 시각화 옵션과 대시보드 템플릿을 제공하며, 사용자 정의 대시보드를 만들고 경고 규칙을 설정할 수 있습니다.


3. AlertManager: AlertManager는 Prometheus에서 수집한 경고를 처리하고 관리하는 도구입니다. Prometheus에서 생성된 경고를 수신하고, 해당 경고에 대한 조치를 취하거나 다른 시스템으로 전송할 수 있습니다. 예를 들어, 이메일, Slack, PagerDuty 등의 경고 채널로 알림을 보낼 수 있습니다.


4. Operator: Prometheus Operator는 Kubernetes 클러스터에서 Prometheus와 관련된 리소스를 관리하는 도구입니다. Operator를 사용하면 Prometheus 리소스, ServiceMonitor, Alertmanager 및 Grafana와 같은 Prometheus Stack 구성 요소를 Kubernetes에서 쉽게 배포, 관리 및 확장할 수 있습니다.


5. kube-state-metrics: kube-state-metrics는 Kubernetes 클러스터의 상태를 메트릭으로 수집하는 컴포넌트입니다. 노드, 파드, 서비스, 볼륨 등의 Kubernetes 리소스에 대한 메트릭을 제공합니다. 이러한 메트릭은 Prometheus에서 사용되어 Kubernetes 클러스터의 상태를 모니터링하고 분석하는 데 사용됩니다.


6. node-exporter: node-exporter는 Prometheus Exporter 중 하나로, 호스트 머신의 메트릭을 수집하는 역할을 합니다. CPU, 메모리, 디스크, 네트워크 등의 시스템 메트릭을 수집하고 Prometheus에 노출하여 모니터링할 수 있습니다. node-exporter는 각 노드에서 실행되며, Prometheus가 이를 타겟으로 설정하여 노드의 상태 및 성능을 추적할 수 있습니다.

 

 

3. Grafana 접속

3-1. Grafana Pod Port Fowarding

kubectl port-forward services/prometheus-stack-grafana 3000:3000

localhost:3000 접속

3-2. ID/Password 확인

ID: admin

PW는 아래 명령어를 입력시 출력

(따라오셨다면 prom-operator 나타날겁니다.)

kubectl get secret -n managed prometheus-stack-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

 

로그인화면

4. 정상적으로 동작하는지 확인

 

5. 삭제

helm uninstall prometheus-stack

 

 

반응형