k8s 및 인프라/prometheus

grafana metric 수집이슈

DanielZZI 2024. 3. 15. 03:27
728x90

grafana exporter 및 servicemonitor 셋업을 하고 prometheus에 잘수집되는지 확인해보았더니 다음과같은 에러가 났다.

 

x509: certificate signed by unknown authority for prometheus

Hi,

 

사실 이 에러자체는 prometheus에 tls insecure설정을 함으로써 회피가 가능하나. 나는 그것외에도 특이한점을 발견했다.

 

endpoint는 pod ip:pod port/metrics 로 되어있는데

ERROR로그에는 Get <k8s cluster DNS>:<istio ingressgateway port>/metrics로 redirect되어있는것이다.

 

이로인해 발생한 에러였고, 이 원인을 먼저확인해야했다.

 

k8s서버에서 curl pod ip:pod port를 날리면 아래와 같이 redirect 경로를 return해준다.

<a href="grafana url/metrics"> Moved Permanently< /a>

 

이는 redirected url을 리턴해준거고, 어디서 이 redirect설정이 걸린건지 를 보자.

 

istio-proxy를 sidecar로 가진 grafana에 요청이오는 경로를 보면

 

1.istio-sidecar를 사용하는 pod에 요청을 보내면 istio-proxy가 받는다.

2.istio-proxy는 envoy proxy를 통해 요청을 intercept하고 istio의 다양한 기능을 적용한다.

3.istio-proxy는 이 요청을 가지고 istio의 아래 각 istio 리소스를 거치게된다.

-gateway

-virtualservice

-destinationrule

4. 이러한 과정을 거쳐서 요청을 실제 타겟 pod app으로 전달된다.

5.app역시 response를 istio-proxy를 거쳐 client로 전달한다.

 

각 단계에서 redirect 설정을 걸만한 부분은 virtualservice나 istio-proxy정도일텐데, 나는 따로 설정을 하지 않았다.

 

그렇다면 app(grafana)설정을 봐야하는데,

 

해당 이슈를 구글링을 통해 찾을수 있었다.

 

https://github.com/grafana/grafana/issues/72577#issuecomment-1682277779

 

Behavior of "serve_from_sub_path" changes in Grafana v10 · Issue #72577 · grafana/grafana

What happened? When using reverse proxy to serve Grafana from a sub path, we've been setting serve_from_sub_path to true in Grafana v7, v8 and v9. When upgrading to v10, the behavior of this parame...

github.com

 

 

When serve_from_subpath is enabled, internal requests from e.g. prometheus get redirected to the defined root_url.
This is causing prometheus to not be able to scrape metrics because it accesses grafana via the kubernetes service name and is then redirected to the public url, which is in our case behind a oauth2 proxy.

When serve_from_subpath is disabled, no redirect is happening and prometheus can successfully scrape the service endpoint.

 

나는 istio-ingressgateway를 통해 grafana를 subpath로 base_url을 설정하여 구동하고 있었고

이과정에서 grafana configuration의 serv_from_subpath = true로 설정하고 있었다. 

이를 통해 자동으로 외부 url로 redirect되었다.

 

1.grafana config변경 후 grafana재시작

serve_from_sub_path = true => false

 

2.istio virtualservice  아래 추가

rewrite:

  url: /

 

 

로 변경후

 

정상적으로 grafana metric이 수집됨을 확인했다.

'k8s 및 인프라 > prometheus' 카테고리의 다른 글

prometheus operator- alertmanagerConfig  (0) 2024.03.30
prometheus operator  (0) 2024.03.16
prometheus operator  (0) 2024.03.15