Search
Duplicate

kube-Prometeous

Prometheus 및 Prometheus Operator를 기반으로 하는 전체 클러스터 모니터링 스택에 대한 예제 구성을 제공하는 프로젝트로 Grafana 도 포함되어 있다.
Prometheus : 메트릭 기반의 오픈소스 모니터링 시스템
Prometheus Operator : Prometheus 및 관련 모니터링 구성 요소 의 Kubernetes 기본 배포 및 관리를 제공합니다. 이 프로젝트의 목적은 Kubernetes 클러스터에 대한 Prometheus 기반 모니터링 스택의 구성을 단순화하고 자동화
Grafana : 오픈소스 메트릭 데이터 시각화 도구로 메트릭 분석 플랫폼

Architecture

Push gateway : Proxy forwarding 을 통해 접근할 수 없는 곳에 데이터가 존재 할경우 사용 할 수 있는 대안application 이 pushgateway에 push 후 prometheus 서버가 metric 을 pull 하는 방식으로 동작
Jobs/Exporter : 프로메테우스에 메트릭을 가져가도록 특정 서비스에 metric을 노출하게 하는 agent Exporter는 서버 상태를 나타내는 Node Exporter, SQL Exporter 등 다양한 커스텀 Exporter 가 있다.
Prometheus 는 Pull 방식을 사용한다. (서버가 클라이언트에 요청해서 수집)
Service discovery : 데이터 수집 대상 목록을 유지
Alert Manager : PromQL 로 실행된 모든 결과는 알림으로 발생, 이 알림 중 특정 알림에 대해 Rule 을 만들어서 pagerduty, Email 등으로 전송이 가능하게 한다.
PromQL : Prometheus 는 metric 이름 및 키/값 쌍으로 식별되는 시계열 데이터가 있는 다차원 데이터 모델이고 이러한 차원을 활용하는 유연한 쿼리 언어가 PromQL 이다. 그라파나 등에서 다양한 그래프 및 대시보드를 지원하며 코드계측을 위한 라이브러리 등을 지원한다
Reference

왜 사용하는가?

Cloud Native 환경에서는 Container 기반의 Application 을 작게 운영하고 필요 할 때 마다 확장, 파괴하는 방식을 선택한다.
동적으로 확장하는 서버에 agent 를 일일이 설치 불가능 하므로, kube api 를 통해 동적으로 확장된 서버 endpoint 를 discovery 하는 방식으로 운영 된다.
Legacy
Cloud

Install

설치는 쉽다, 다만 커스텀 구성이 복잡.
# clone git clone https://github.com/prometheus-operator/kube-prometheus.git # apply kubectl apply --server-side -f manifests/setup kubectl wait \ --for condition=Established \ --all CustomResourceDefinition \ --namespace=monitoring kubectl apply -f manifests/ # get $ k get po -n monitoring NAME READY STATUS RESTARTS AGE alertmanager-main-0 2/2 Running 1 (12m ago) 14m alertmanager-main-1 2/2 Running 0 14m alertmanager-main-2 2/2 Running 1 (11m ago) 14m blackbox-exporter-c5547b8bb-xn8ng 3/3 Running 0 19m grafana-7c4645d965-mhpbc 1/1 Running 0 19m kube-state-metrics-8658546b69-ffqhg 3/3 Running 0 19m node-exporter-6rzrv 2/2 Running 0 19m node-exporter-dvztx 2/2 Running 0 19m node-exporter-jcndt 2/2 Running 0 19m node-exporter-w8txr 2/2 Running 0 19m prometheus-adapter-678b454b8b-dqtpx 1/1 Running 0 19m prometheus-adapter-678b454b8b-z8fxm 1/1 Running 0 19m prometheus-k8s-0 2/2 Running 0 14m prometheus-k8s-1 2/2 Running 0 14m prometheus-operator-5ddfd64d6-t2xhh 2/2 Running 0 19m # get svc $ k get svc -n monitoring NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE alertmanager-main ClusterIP 10.101.243.10 <none> 9093/TCP,8080/TCP 29h alertmanager-operated ClusterIP None <none> 9093/TCP,9094/TCP,9094/UDP 29h blackbox-exporter ClusterIP 10.101.121.129 <none> 9115/TCP,19115/TCP 29h grafana ClusterIP 10.105.181.43 <none> 3000/TCP 29h kube-state-metrics ClusterIP None <none> 8443/TCP,9443/TCP 29h node-exporter ClusterIP None <none> 9100/TCP 29h prometheus-adapter ClusterIP 10.108.197.78 <none> 443/TCP 29h prometheus-k8s ClusterIP 10.107.240.221 <none> 9090/TCP,8080/TCP 29h prometheus-operated ClusterIP None <none> 9090/TCP 29h prometheus-operator ClusterIP None <none> 8443/TCP 29h
Bash
복사
설치된 pods 를 보면 alertmanager, exporter, grafana, metrics, prometheus 3종이 설치 된다.
기본적으로 서비스도 모두 등록이 되며 grafana : 3000/tcp, Prometheus : 9090/tcp, Alert Manager : 9093/tcp
들이 테스트 하며 접속해야 할 서비스들이다.

Ingress 설치 with helm

helm 사용 이유
helm 은 단순하게 apt 처럼 패키지 다운로드 역할 뿐만 아니라 yaml 파일들을 관리하기 위한 필수적인 방법이다.
유연한 버전관리, 즉각 대응, 가독성 향상, 불필요 파일 최소화 등 많은 이점을 가져갈수 있다.
helm 설치
curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null sudo apt-get install apt-transport-https --yes echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list sudo apt-get update sudo apt-get install helm
Bash
복사

helm 으로 ingress-nginx 설치

ingress-nginx의 경우 kubernetes 에서 배포하는 ingress 와 nginx 에서 배포하는 ingress가 있다
기존에 사용하던 kubernets 에서 배포하는 ingress 사용
# repo 등록 helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo update # 버전 관리를 위해 helm image pull helm pull ingress-nginx/ingress-nginx # 설치 helm install ingress ingress-nginx/ingress-nginx --namespace ingress-nginx # 확인 $ helm list -A NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION ingress ingress-nginx 1 2022-10-12 16:40:04.011246769 +0900 KST deployed ingress-nginx-4.3.0 1.4.0
Bash
복사
# grafana-ing apiVersion: networking.k8s.io/v1 kind: Ingress metadata: annotations: #kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/rewrite-target: / name: grafana-ing namespace: monitoring spec: ingressClassName: nginx rules: - http: paths: - path: / pathType: Prefix backend: service: name: grafana-svc port: number: 3000
YAML
복사