Istio Prometheus 메트릭 수집 및 Grafana 연동

이번 포스트에서는 Istio, Prometheus, Grafana 통합 방법에 대해 알아보겠습니다. 이 세 가지 도구는 마이크로서비스 아키텍처에서 효과적인 모니터링과 트래픽 관리를 지원하며, 함께 사용하면 서비스의 성능과 안정성을 극대화할 수 있습니다.

우선 Istio를 통해 서비스 간의 통신을 관리하고, Prometheus를 사용하여 메트릭을 수집 및 저장한 뒤, Grafana로 이를 시각화하여 실시간으로 모니터링할 수 있는 대시보드를 구축하는 방법을 단계별로 설명하겠습니다. 이를 통해 여러분의 시스템을 더욱 효과적으로 관리하고 인사이트를 얻는 데 도움이 되고자 합니다.

목차

1. Istio란?
2. Prometheus란?
3. Grafana란?
4. Istio, Prometheus, Grafana 통합하는 방법
4-1. 환경 구성
4-2. Istio 설치
4-3. Grafana 설치
5. 모니터링 대시보드 구성
6. 결론

1. Istio란?

Istio는 서비스 메쉬를 관리하기 위한 오픈 소스 플랫폼입니다. 이는 서비스 간의 통신을 제어하고 보안을 강화하며, 다양한 정책을 적용할 수 있게 해줍니다. Istio를 사용하면 트래픽 관리, 보안, 관찰 가능성을 한 곳에서 처리할 수 있어 효율적인 운영이 가능합니다.

2. Prometheus란?

Prometheus는 시스템 모니터링과 경고를 위한 오픈 소스 도구입니다. 시계열 데이터베이스를 사용하여 시간에 따른 다양한 메트릭을 수집하고 저장할 수 있습니다. 주로 Kubernetes와 함께 사용되어 클러스터의 성능을 모니터링하고 이상 징후를 조기에 발견할 수 있도록 도와줍니다.

3. Grafana란?

Grafana는 다양한 데이터 소스로부터 메트릭을 시각화할 수 있는 대시보드 플랫폼입니다. Prometheus와 함께 사용하여 수집한 데이터를 시각적으로 모니터링할 수 있으며, 사용자 정의 대시보드를 통해 필요한 정보를 즉시 확인할 수 있습니다.

4. Istio, Prometheus, Grafana 통합하는 방법

4-1. 환경 구성

Kubernetes 클러스터를 준비합니다. 이 클러스터는 Istio와 Prometheus, Grafana를 설치할 환경이 됩니다. 클러스터가 정상적으로 작동하는지 확인합니다.

환경 정보:

  • kubernetes v1.32.1
  • istio v1.24.2

4-2. Istio 설치

작성일 기준 Istio의 최신 버전(1.24.2)을 설치합니다.

$ curl -L https://istio.io/downloadIstio | sh -

istioctl 사용을 위해 클라이언트 경로를 추가합니다.

$ cd istio-1.24.2

$ export PATH=$PWD/bin:$PATH

$ istioctl version

client version: 1.24.2
control plane version: 1.24.2
data plane version: 1.24.2 (8 proxies)

필요한 최소한의 리소스 배포를 배포합니다.

$ istioctl install --set profile=default

$ kubectl get pods,svc -n istio-system
NAME                                        READY   STATUS    RESTARTS   AGE
pod/istio-ingressgateway-67fb649dc8-s24hs   1/1     Running   0          65m
pod/istiod-86d96548d6-blq2r                 1/1     Running   0          65m

NAME                           TYPE           CLUSTER-IP       EXTERNAL-IP       PORT(S)                                      AGE
service/istio-ingressgateway   LoadBalancer   10.98.139.33     192.168.201.112   15021:32244/TCP,80:31785/TCP,443:32707/TCP   65m
service/istiod                 ClusterIP      10.96.212.224    <none>            15010/TCP,15012/TCP,443/TCP,15014/TCP        65m

profile 별로 배포되는 리소스는 아래와 같습니다.

defaultdemominimalremoteemptypreviewambient
Core components
istio-egressgateway
istio-ingressgateway
istiod
CNI
Ztunnel

4-3. Prometheus 설치

4-2 섹션에서 설치한 istio-1.24.2/samples/addons/ 하위에 있는 Istio에서 제공하는 prometheus.yaml을 배포합니다.

$ kubectl apply -f istio-1.24.2/samples/addons/prometheus.yaml

$ kubectl get pods,svc -n istio-system
NAME                                        READY   STATUS    RESTARTS   AGE
pod/istio-ingressgateway-67fb649dc8-s24hs   1/1     Running   0          65m
pod/istiod-86d96548d6-blq2r                 1/1     Running   0          65m
pod/prometheus-65dbd67cfd-6gw47             2/2     Running   0          22m

NAME                           TYPE           CLUSTER-IP       EXTERNAL-IP       PORT(S)                                      AGE
service/istio-ingressgateway   LoadBalancer   10.98.139.33     192.168.201.112   15021:32244/TCP,80:31785/TCP,443:32707/TCP   65m
service/istiod                 ClusterIP      10.96.212.224    <none>            15010/TCP,15012/TCP,443/TCP,15014/TCP        65m
service/prometheus             ClusterIP      10.100.176.100   <none>            9090/TCP                                     22m

prometheus가 정상적으로 배포되면 istio-system namespace에 9090 포트로 활성화되게 됩니다. 이를 브라우저에서 확인하기 위해 Gateway 리소스와 VirtualService 리소스를 배포합니다.

apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
  name: prom-gateway
  namespace: istio-system
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "prom.example.com"  # 접속할 도메인 또는 IP 주소
---
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
  name: prom-virtualservice
  namespace: istio-system
spec:
  hosts:
  - "prom.example.com"  # 도메인 또는 IP 주소
  gateways:
  - prom-gateway  # 앞에서 만든 Gateway와 연결
  http:
  - match:
    - uri:
        prefix: "/"
    route:
    - destination:
        host: prometheus
        port:
          number: 9090  # prometheus의 포트 번호

배포된 내용은 아래와 같습니다.

$ kubectl get gateway,virtualservice -n istio-system
NAME                                       AGE
gateway.networking.istio.io/prom-gateway   147m

NAME                                                     GATEWAYS           HOSTS                  AGE
virtualservice.networking.istio.io/prom-virtualservice   ["prom-gateway"]   ["prom.example.com"]   147m

브라우저에서 prom.example.com에 접속하여 프로메테우스를 통해 istio의 메트릭을 확인할 수 있습니다.

istio prometheus grafana

4-4. Grafana 설치

4-2 섹션에서 설치한 istio-1.24.2/samples/addons/ 하위에 있는 Istio에서 제공하는 grafana.yaml을 배포합니다.

$ kubectl apply -f istio-1.24.2/samples/addons/grafana.yaml

$ kubectl get pods,svc -n istio-system
NAME                                        READY   STATUS    RESTARTS   AGE
pod/grafana-5c8796b75b-j5wwr                1/1     Running   0          21m
pod/istio-ingressgateway-67fb649dc8-s24hs   1/1     Running   0          3h9m
pod/istiod-86d96548d6-blq2r                 1/1     Running   0          3h9m
pod/prometheus-65dbd67cfd-6gw47             2/2     Running   0          146m

NAME                           TYPE           CLUSTER-IP       EXTERNAL-IP       PORT(S)                                      AGE
service/grafana                ClusterIP      10.109.110.172   <none>            3000/TCP                                     21m
service/istio-ingressgateway   LoadBalancer   10.98.139.33     192.168.201.112   15021:32244/TCP,80:31785/TCP,443:32707/TCP   3h9m
service/istiod                 ClusterIP      10.96.212.224    <none>            15010/TCP,15012/TCP,443/TCP,15014/TCP        3h9m
service/prometheus             ClusterIP      10.100.176.100   <none>            9090/TCP                                     146m

grafana가 정상적으로 배포되면 istio-system namespace에 3000 포트로 활성화되게 됩니다. 이를 브라우저에서 확인하기 위해 Gateway 리소스와 VirtualService 리소스를 배포합니다.

apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
  name: grafana-gateway
  namespace: istio-system  # 해당 네임스페이스에 맞게 설정
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "grafana.example.com"  # 접속할 도메인 또는 IP 주소
---
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
  name: grafana-virtualservice
  namespace: istio-system  # 해당 네임스페이스에 맞게 설정
spec:
  hosts:
  - "grafana.example.com"  # 도메인 또는 IP 주소
  gateways:
  - grafana-gateway  # 앞에서 만든 Gateway와 연결
  http:
  - match:
    - uri:
        prefix: "/"
    route:
    - destination:
        host: grafana
        port:
          number: 3000  # grafana의 포트 번호

배포된 내용은 아래와 같습니다.

$ kubectl get gateway,virtualservice -n istio-system
NAME                                          AGE
gateway.networking.istio.io/grafana-gateway   43m
gateway.networking.istio.io/prom-gateway      3h27m

NAME                                                        GATEWAYS              HOSTS                     AGE
virtualservice.networking.istio.io/grafana-virtualservice   ["grafana-gateway"]   ["grafana.example.com"]   43m
virtualservice.networking.istio.io/prom-virtualservice      ["prom-gateway"]      ["prom.example.com"]      3h27m

브라우저에서 grafana.example.com에 접속하여 메트릭을 시각화하여 확인할 수 있습니다.

istio prometheus grafana

좌측 메뉴에서 Dashboards를 클릭하여 Istio에서 제공하는 Dashboard를 확인할 수 있습니다.

istio prometheus grafana

5. 모니터링 대시보드 구성

Istio에서는 다양한 메트릭을 대시보드로 분류하여 제공합니다.

Istio Control Plane Dashboard는 리소스 사용량, Push 정보, Webhook 정보를 제공합니다.

istio prometheus grafana

Istio Mesh Dashboard는 글로벌 트래픽, 워크로드 정보를 제공합니다.

Istio Performance Dashboard는 Istio의 리소스 사용량을 주로 제공합니다.

Istio Service Dashboard는 서비스 별 성능과 상태 등을 확인할 수 있습니다.

Istio Workload Dashboard는 workload에 대한 자세한 정보를 제공합니다.

위 대시보드들을 제외한 Istio Wasm Extension Dashboard와 Istio Ztunnel Dashboard도 제공합니다.

6. 결론

Istio, Prometheus, Grafana의 통합은 마이크로서비스 아키텍처에서 필수적인 요소입니다. 이 세 가지 도구를 통해 서비스의 성능을 극대화하고 안정성을 높일 수 있습니다.

Prometheus의 메트릭 수집과 Grafana의 시각화 기능이 결합되어, Istio로 관리되는 서비스의 상태를 실시간으로 모니터링할 수 있습니다. 이를 통해 운영자의 부담을 줄이고, 서비스의 전반적인 품질을 향상시킬 수 있습니다.

Istio와 Kiali를 구성하는 방법은 아래 포스트를 확인해주세요.

NGINX STORE를 통한 솔루션 도입 및 기술지원 무료 상담 신청

* indicates required