카테고리 없음

[Kubernetes] Prometheus & Grafana

JungGwig 2019. 12. 29. 16:41

기능

 

  • 시계열(Time Series) 데이터를 저장할 수 있는 다차원(Multi-Dimensional) 데이터 모델과 이 데이터 모델을 효과적으로 활용할 수 있는 PromQL이라는 쿼리 언어로 되어 있다.

  • 기본적인 데이터 수집은 pull 구조로 되어 있어서 서버가 수집하려는 대상에게서 데이터를 가져오도록 되어 있다.

  • 수집대상은 정적으로 설정가능하며 Service Discovery를 통해서 동적으로 설정하는 것도 가능하다.

  • 기본적인 데이터 수집은 pull 구조로 되어 있지만 외부에서 직접 Push한 데이터를 PushGateway를 통해서 저장할 수 있다.

  • 데이터 저장은 단순하게 디스크에 저장 가능하고 외부 스토리지에 저장하는 것도 가능하다.

 

아키텍처

 

 

사용법

 

1. prometheus를 위한 namespace 생성

2. 환경 변수 설정을 위한 Configmap을 만든다.

Configmap File : https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml

3. 프로메테우스용 디플로이먼트와 서비스 생성

 

 

 

 

문제점

 

1. Prometheus와 Grafana를 이용한 모니터링을 위한 네임스페이스를 별도로 만들어서 Configmap, deployment, Service, PV에 네임스페이스를 지정하였다. 프로메테우스에서 기본적으로 제공하는 config의 service endpoint의 namespace가 default로 지정되어 있었기 때문에 pod에서 namespace가 변경된 svc를 찾을 수 없어서 데이터를 제대로 읽어오지 못하는 문제가 있었다.

--> Pod에서 API 액세스 실패 : Failed to list *v1.Service: services is forbidden: User \"system:serviceaccount:prometheus-k8s:default\" cannot list resource \"services\" in API group \"\" at the cluster scope"

 

Background

1. Prometheus Configuration File

 - Generic placeholders

<boolean> true || false
<duration> duration [0-9]+(ms|[smhdwy])
<labelname> string    [a-zA-Z_][a-zA-Z0-9_]*
<labelvalue> a string of unicode characters
<filename> a valid path in the current working directory
<host> a valid string consisting of a hostname or IP followed by an optional port number
<path> a valid URL path
<scheme> a string that can take the values http or https
<string> a regular string
<secret> a regular string that is a secret, such as a password

<kubernetes_sd_config>

role

- service : 일반적으로 서비스의 블랙 박스 모니터링에 유용, 주소는 서비스 및 해당 서비스 포트의 Kubernetes DNS 이름으로 설정됩니다.

  • __meta_kubernetes_namespace : The namespace of the service object
  • __meta_kubernetes_service_cluster_ip : The cluster IP address of the services
  • __meta_kubernetes_service_name : The name of the service object
  • __meta_kuberntes_service_port_protocol : Protocol of the service port for the target

- endpoint

2. 파드에서 API Access

 

파드 내에서 apiserver의 위치를 지정하는데 추천하는 방식은 kubernetes.default.svc DNS 네임을 사용하는 것이다. 이 DNS 네임은 apiserver로 라우팅되는 서비스 IP로 resolve된다.