Prometheus

[Prometheus] Prometheus Operator

hihikiki 2023. 7. 26. 14:43

Prometheus Operator  나왔을까?

Prometheus VM이나 k8s 등에 설치가 가능합니다 근데 k8s 설치하면 임시적이고, 비영구적인 Pod기반이기 때문에 프로메테우스 구성요소와 메트릭 수집 대상 관리가 힘듭니다.

게다가 프로메테우스는 시스템 내부의 yaml config(prometheus.yml) 파일 기준으로 설정을 유지하는데, k8s환경에서는 컨테이너 내부 파일을 변경하기가 번거롭습니다.

 

뭐가 번거롭냐..?

어플리케이션의 metric수집을 위해서 exporter 설치하면, 프로메테우스가  exporter에서 메트릭을 끌어올  있도록 scrape 대상을 추가해줘야합니다. scrape 대상을 추가하기 위해서 Prometheus 컨테이너안으로 들어가서 ‘prometheus.yml’ 파일을 열어서 scrap 대상을 직접 추가해줘야합니다.

global:
  # 기본적인 설정은 여기에 위치

scrape_configs:
  - job_name: 'node_exporter'
    static_configs:
      - targets: ['<Node Exporter의 IP 주소>:9100']

 

심지어 ‘prometheus.yml’ 파일에 스크랩 대상을 추가하고 저장하면 Prometheus 인스턴스를 재시작해야합니다. ‘prometheus.yml’ 파일은 Prometheus 서비스가 시작될    읽히기 때문에  파일을 수정한  변경 사항을 적용하려면 Prometheus 재시작해야 합니다.

프로메테우스 인스턴스를 재시작하면  사이동안 metric 수집도 안되는....

 

그래서 이런 불편함을 줄이기 위해 Prometheus Operator 등장

 

Prometheus Operator 아키텍처

 

CRD 구성된 Prometheus Rule, Service Monitor, Prometheus, AlertManager 등의 ResourcePrometheus Operator watch하고, update 정보를 기반으로 Prometheus config(rulefile, config.yaml) 업데이트하고 prometheus, Alert Manager container(Pod) 업데이트 합니다.

 

Prometheus Operator Resource

  • Prometheus: Kubernetes 클러스터 내에서 Prometheus 서버의 인스턴스를 배포하고 구성하는 역할
  • Alertmanager: 알람 규칙을 적용하고 알림을 관리하는 리소스
  • ServiceMonitor: 프로메테우스가 모니터링 하는 대상을 정의
  • PrometheusRule: Prometheus 모니터링 하는 대상에 어떤 문제가 있을  Alert 발생시킵니다. 이때  문제가 무엇이냐를 정의하는 경고 규칙을 정의하는 리소스

 

정리하면 Prometheus리소스를 통해 Prometheus  배포하고, 모니터링하는 대상을 ServiceMonitor정의, 모니터링 대상의 Alert Rule PrometheusRule 정의, 정의된 rule대로 알람 규칙을 적용하고 알림을 관리하는  AlertManager입니다.

 

Prometheus Prometheus, config-reload 2ea controller pod 구성하며prometheus rule 정의한 rulefile config정보인 config.yaml 업데이트  때마다 config-reload 통해 pod 재시작없이 해당 내용을 prometheus 반영합니다.

 

참고로...

Prometheus Operator에서 watch하는 대상인 resource spec prometheus operator 소스에서정의합니다. 정의되어 있지 않은 spec 대한 정보는 컨트롤   없으며 일반적으로 고정값을 지녀서 변경할 필요없는 대상이 제외되었거나 or 필요한 내용임을 인지하지 못한 탓에 제외되누 경우가 있으며 이런경우 github issue 제기되면 앞으로 추가 구현해야할 spec으로 정의되어 구현됩니다.