Theory
인프라
Loki 공식 문서 번역
setup
모니터링
Grafana Cloud로 모니터링

Grafana Cloud로 Loki 모니터링하기

원본: https://grafana.com/docs/loki/latest/setup/install/helm/monitor-and-alert/with-grafana-cloud/ (opens in a new tab)

이 가이드는 meta-monitoring Helm 차트로 설정된 Loki 설치를 Grafana Cloud를 사용하여 모니터링하는 방법을 안내합니다. 이 방법은 차트의 많은 자체 모니터링 기능을 활용하여 Loki 배포에서 메트릭, 로그 및 추적을 Grafana Cloud로 보냅니다. Grafana Cloud로 Loki를 모니터링하면 원격 측정 데이터가 Grafana Cloud 인스턴스에서 계속 사용 가능하므로 Helm으로 설치된 Loki가 다운되었을 때도 Loki 문제를 해결할 수 있는 추가적인 이점이 있습니다.

이 지침은 meta-monitoring-chart 저장소 (opens in a new tab)를 기반으로 합니다.

시작하기 전에

  • Helm 3 이상. Helm 설치 (opens in a new tab)를 참조하세요.
  • Grafana Cloud 계정 및 스택(Cloud Grafana, Cloud Metrics 및 Cloud Logs 포함).
  • 해당 쿠버네티스 클러스터에 Helm 차트를 통해 설치된 실행 중인 Loki 배포.

meta 네임스페이스 구성

메타 모니터링 스택은 meta라는 별도의 네임스페이스에 설치됩니다. 이 네임스페이스를 생성하려면 다음 명령을 실행하세요:

kubectl create namespace meta

Grafana Cloud 연결 자격 증명

메타 모니터링 스택은 메트릭, 로그 및 추적을 Grafana Cloud로 보냅니다. 이를 위해서는 Grafana Cloud에 대한 연결 자격 증명을 알아야 합니다. 연결 자격 증명을 얻으려면 아래 단계를 따르세요:

  1. Grafana Cloud에서 새 클라우드 액세스 정책을 생성합니다.

    • Grafana Cloud (opens in a new tab)에 로그인합니다.
    • 주 메뉴에서 Security > Access Policies를 선택합니다.
    • Create access policy를 클릭합니다.
    • 정책에 이름을 지정하고 다음 권한을 선택합니다:
      • Metrics: Write
      • Logs: Write
      • Traces: Write
  2. Create를 클릭합니다.

  3. 정책이 생성되면 정책을 선택하고 Add token을 클릭합니다.

  4. 토큰의 이름을 지정하고 만료 날짜를 선택한 다음 Create를 클릭합니다.

  5. 토큰은 다시 표시되지 않으므로 안전한 위치에 복사합니다.

  6. Grafana Cloud 포털 개요 페이지로 이동합니다.

  7. Prometheus 또는 Mimir 인스턴스의 Details 버튼을 클릭합니다.

    • Using a self-hosted Grafana instance with Grafana Cloud Metrics 섹션에서 인스턴스 이름URL을 수집합니다.
    • 개요 페이지로 다시 이동합니다.
  8. Loki 인스턴스의 Details 버튼을 클릭합니다.

    • Using Grafana with Logs 섹션에서 인스턴스 이름URL을 수집합니다.
    • 개요 페이지로 다시 이동합니다.
  9. Tempo 인스턴스의 Details 버튼을 클릭합니다.

    • Using Grafana with Tempo 섹션에서 인스턴스 이름URL을 수집합니다.
  10. 마지막으로, 쿠버네티스 클러스터 내에서 각 메트릭 유형에 대한 자격 증명을 저장할 시크릿을 생성합니다:

    kubectl create secret generic logs-creds -n meta \
      --from-literal=username=<USERNAME_LOGS> \
      --from-literal=password=<ACCESS_POLICY_TOKEN> \
      --from-literal=endpoint='https://<LOG_URL>/loki/api/v1/push'
     
    kubectl create secret generic metrics-creds -n meta \
      --from-literal=username=<USERNAME_METRICS> \
      --from-literal=password=<ACCESS_POLICY_TOKEN> \
      --from-literal=endpoint='https://<METRICS_URL>/api/prom/push'
     
    kubectl create secret generic traces-creds -n meta \
      --from-literal=username=<OTLP_INSTANCE_ID> \
      --from-literal=password=<ACCESS_POLICY_TOKEN> \
      --from-literal=endpoint='https://<OTLP_URL>/otlp'

구성 및 설치

meta-monitoring Helm 차트를 설치하려면 values.yaml 파일을 생성해야 합니다. 최소한 이 파일에는 다음이 포함되어야 합니다:

  • 모니터링할 네임스페이스
  • 클라우드 모니터링 활성화

이 예제 values.yaml 파일은 loki 네임스페이스를 모니터링하기 위한 최소 구성을 제공합니다:

values.yaml
namespacesToMonitor:
  - default
 
cloud:
  logs:
    enabled: true
    secret: "logs-creds"
  metrics:
    enabled: true
    secret: "metrics-creds"
  traces:
    enabled: true
    secret: "traces-creds"

추가 구성 옵션은 샘플 values.yaml 파일 (opens in a new tab)을 참조하세요.

meta-monitoring Helm 차트를 설치하려면 다음 명령을 실행하세요:

helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
helm install meta-monitoring grafana/meta-monitoring -n meta -f values.yaml

구성을 업그레이드할 때는:

helm upgrade meta-monitoring grafana/meta-monitoring -n meta -f values.yaml

설치를 확인하려면 다음 명령을 실행하세요:

kubectl get pods -n meta

다음과 같은 파드가 반환되어야 합니다:

NAME           READY   STATUS    RESTARTS   AGE
meta-alloy-0   2/2     Running   0          23h
meta-alloy-1   2/2     Running   0          23h
meta-alloy-2   2/2     Running   0          23h

Loki 추적 활성화

기본적으로 Loki는 추적이 활성화되어 있지 않습니다. 추적을 활성화하려면 values.yaml 파일을 편집하여 Loki 구성을 수정하고 다음 구성을 추가하세요:

tracing.enabled 구성을 true로 설정합니다:

values.yaml
loki:
  tracing:
    enabled: true

다음으로, 각 Loki 구성 요소가 메타 모니터링 스택으로 추적을 보내도록 계측합니다. 각 Loki 구성 요소에 extraEnv 구성을 추가합니다:

values.yaml
ingester:
  replicas: 3
  extraEnv:
    - name: JAEGER_ENDPOINT
      value: "http://mmc-alloy-external.default.svc.cluster.local:14268/api/traces"
      # This sets the Jaeger endpoint where traces will be sent.
      # The endpoint points to the mmc-alloy service in the default namespace at port 14268.
    - name: JAEGER_AGENT_TAGS
      value: "'cluster=\"prod\",namespace=\"default\"'"
      # This specifies additional tags to attach to each span.
      # Here, the cluster is labeled as "prod" and the namespace as "default".
    - name: JAEGER_SAMPLER_TYPE
      value: "ratelimiting"
      # This sets the sampling strategy for traces.
      # "ratelimiting" means that traces will be sampled at a fixed rate.
    - name: JAEGER_SAMPLER_PARAM
      value: "1.0"
      # This sets the parameter for the sampler.
      # For ratelimiting, "1.0" typically means one trace per second.

메타 모니터링 스택이 meta 네임스페이스에 설치되어 있으므로, Loki 구성 요소는 메타 모니터링 스택과 통신할 수 있어야 합니다. 이를 위해 다음 명령을 실행하여 default 네임스페이스에 meta 네임스페이스를 가리키는 새로운 externalname 서비스를 생성합니다:

kubectl create service externalname mmc-alloy-external --external-name meta-alloy.meta.svc.cluster.local -n default

마지막으로, 새 구성으로 Loki 설치를 업그레이드합니다:

helm upgrade --values values.yaml loki grafana/loki

Grafana Cloud로 Loki 대시보드 가져오기

메타 모니터링 스택에는 Grafana Cloud로 가져올 수 있는 대시보드 세트가 포함되어 있습니다. 이는 meta-monitoring 저장소 (opens in a new tab)에서 찾을 수 있습니다.

규칙 설치

메타 모니터링 스택에는 Loki 설치를 모니터링하기 위해 설치할 수 있는 규칙 세트가 포함되어 있습니다. 이 규칙은 meta-monitoring 저장소 (opens in a new tab)에서 찾을 수 있습니다. 규칙을 설치하려면:

  1. 저장소를 복제합니다:
    git clone https://github.com/grafana/meta-monitoring-chart/
  2. 여기에 있는 지침에 따라 mimirtool을 설치합니다.
  3. 다음 권한으로 Grafana Cloud에서 새 액세스 정책 토큰을 생성합니다:
    • Rules: Write
    • Rules: Read
  4. 액세스 정책에 대한 토큰을 생성하고 안전한 위치에 복사합니다.
  5. 규칙을 설치합니다:
    mimirtool rules load --address=<your_cloud_prometheus_endpoint> --id=<your_instance_id> --key=<your_cloud_access_policy_token> *.yaml
  6. 규칙이 설치되었는지 확인합니다:
    mimirtool rules list --address=<your_cloud_prometheus_endpoint> --id=<your_instance_id> --key=<your_cloud_access_policy_token>
    설치된 규칙 목록이 반환되어야 합니다.
    loki-rules:
        - name: loki_rules
          rules:
            - record: cluster_job:loki_request_duration_seconds:99quantile
              expr: histogram_quantile(0.99, sum(rate(loki_request_duration_seconds_bucket[5m])) by (le, cluster, job))
            - record: cluster_job:loki_request_duration_seconds:50quantile
              expr: histogram_quantile(0.50, sum(rate(loki_request_duration_seconds_bucket[5m])) by (le, cluster, job))
    # ... (and so on)

kube-state-metrics 설치

쿠버네티스 객체에 대한 메트릭은 kube-state-metrics (opens in a new tab)에서 스크레이핑됩니다. 이는 클러스터에 설치되어야 합니다. 메타 모니터링 values.yamlkubeStateMetrics.endpoint 항목은 해당 주소로 설정되어야 합니다(URL에 /metrics 부분 제외):

values.yaml
kubeStateMetrics:
  # Scrape https://github.com/kubernetes/kube-state-metrics by default
  enabled: true
  # This endpoint is created when the helm chart from
  # https://artifacthub.io/packages/helm/prometheus-community/kube-state-metrics/
  # is used. Change this if kube-state-metrics is installed somewhere else.
  endpoint: kube-state-metrics.kube-state-metrics.svc.cluster.local:8080