로컬 LGTM(Loki, Grafana, Tempo 및 Mimir) 스택을 사용하여 Loki 모니터링하기
이 주제에서는 메타 모니터링 Helm 차트를 사용하여 프로덕션 Loki 설치를 모니터링하는 로컬 스택을 배포하는 방법을 안내합니다. 이 접근 방식은 차트의 많은 자체 모니터링 기능을 활용하지만, 로그를 Loki 자체로 다시 보내는 대신 meta
네임스페이스 내에서 실행되는 작은 LGTM(Loki, Grafana, Tempo, Mimir) 스택으로 보냅니다.
시작하기 전에
- Helm 3 이상. Helm 설치 (opens in a new tab)를 참조하세요.
- 실행 중인 Loki 배포가 있는 실행 중인 쿠버네티스 클러스터.
meta 네임스페이스 구성
메타 모니터링 스택은 meta
라는 별도의 네임스페이스에 설치됩니다. 이 네임스페이스를 생성하려면 다음 명령을 실행하세요:
kubectl create namespace meta
구성 및 설치
메타 모니터링 스택은 meta-monitoring
Helm 차트를 사용하여 설치됩니다. 로컬 모드는 Alloy, Grafana, Mimir, Loki 및 Tempo를 포함하는 작은 LGTM 스택을 배포합니다. 메타 모니터링 스택을 구성하려면 다음 내용으로 values.yaml
파일을 생성하세요:
namespacesToMonitor:
- default
cloud:
logs:
enabled: false
metrics:
enabled: false
traces:
enabled: false
local:
grafana:
enabled: true
logs:
enabled: true
metrics:
enabled: true
traces:
enabled: true
minio:
enabled: true
추가 구성 옵션은 샘플 values.yaml 파일 (opens in a new tab)을 참조하세요.
로컬 모드는 기본적으로 Minio도 활성화하며, 이는 LGTM 스택의 객체 스토리지 역할을 합니다. Minio에 대한 액세스를 제공하려면 일반 시크릿을 생성해야 합니다. 일반 시크릿을 생성하려면 다음 명령을 실행하세요:
kubectl create secret generic minio-creds -n meta \
--from-literal=user=<INSERT USERNAME OF CHOICE> \
--from-literal=password=<INSERT PASSWORD OF CHOICE>
사용자 이름과 비밀번호는 최소 8자 이상이어야 합니다.
메타 모니터링 스택을 설치하려면 다음 명령을 실행하세요:
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
다음과 같은 파드가 반환되어야 합니다:
grafana-59d664f55f-dtfqr 1/1 Running 2 (2m7s ago) 137m
loki-backend-0 2/2 Running 2 (2m7s ago) 137m
loki-backend-1 2/2 Running 4 (2m7s ago) 137m
loki-backend-2 2/2 Running 3 (2m7s ago) 137m
loki-read-6f775d8c5-6t749 1/1 Running 1 (2m7s ago) 137m
loki-read-6f775d8c5-kdd8m 1/1 Running 1 (2m7s ago) 137m
loki-read-6f775d8c5-tsw2r 1/1 Running 1 (2m7s ago) 137m
loki-write-0 1/1 Running 1 (2m7s ago) 137m
loki-write-1 1/1 Running 1 (2m7s ago) 137m
loki-write-2 1/1 Running 1 (2m7s ago) 137m
meta-alloy-0 2/2 Running 2 (2m7s ago) 137m
meta-alloy-1 2/2 Running 2 (2m7s ago) 137m
...
Loki 추적 활성화
기본적으로 Loki는 추적이 활성화되어 있지 않습니다. 추적을 활성화하려면 values.yaml
파일을 편집하여 Loki 구성을 수정하고 다음 구성을 추가하세요:
tracing.enabled
구성을 true
로 설정합니다:
loki:
tracing:
enabled: true
다음으로, 각 Loki 구성 요소가 메타 모니터링 스택으로 추적을 보내도록 계측합니다. 각 Loki 구성 요소에 extraEnv
구성을 추가합니다:
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.
kube-state-metrics 설치
쿠버네티스 객체에 대한 메트릭은 kube-state-metrics (opens in a new tab)에서 스크레이핑됩니다. 이는 클러스터에 설치되어야 합니다. 메타 모니터링 values.yaml
의 kubeStateMetrics.endpoint
항목은 해당 주소로 설정되어야 합니다(URL에 /metrics
부분 제외):
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
메타 모니터링 스택에 액세스하기
메타 모니터링 스택에 액세스하려면 포트 포워딩을 사용하여 Grafana 대시보드에 액세스할 수 있습니다. 이렇게 하려면 다음 명령을 실행하세요:
kubectl port-forward -n meta svc/grafana 3000:3000
대시보드 및 규칙
로컬 메타 모니터링 스택에는 사전 구성된 대시보드 및 경고 규칙 세트가 함께 제공됩니다. 기본 자격 증명인 admin
및 admin
을 사용하여 http://localhost:3000 (opens in a new tab)을 통해 액세스할 수 있습니다.