카테고리 없음

Azure AKS의 Pod 메트릭을 AWS AMP(Amazon Managed Prometheus)로 보내는 방법

idea9329 2025. 2. 12. 21:59
반응형

 

Azure Kubernetes Service(AKS)에서 Pod 메트릭을 수집하고 이를 AWS AMP(Amazon Managed Prometheus)로 전송하는 방법을 설명합니다.


📌 개요

1. AKS에 Prometheus 설치 및 설정

  • AKS 클러스터 내부에서 Prometheus 서버를 실행하여 메트릭을 수집
  • prometheus.yml 파일을 수정하여 AWS AMP로 데이터를 전송

2. AWS AMP에서 수집할 수 있도록 설정

  • AWS IAM 역할 생성 (AWS의 Prometheus에 원격 쓰기 권한 부여)
  • AWS SIGv4 인증을 사용하여 AWS AMP로 데이터 전송

1️⃣ AKS에 Prometheus 설치 및 설정

1. Helm을 사용하여 Prometheus 설치

AKS 클러스터에 Prometheus를 배포합니다.

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/prometheus \
  --namespace monitoring --create-namespace

2. Prometheus 설정 변경

AWS AMP로 데이터를 전송하도록 prometheus.yml을 수정합니다.

  1. Prometheus 설정 파일을 편집:
  2. kubectl edit configmap prometheus-server -n monitoring
  3. 기존 scrape_configs 아래에 AWS AMP Remote Write 설정 추가:
  4. global: scrape_interval: 15s scrape_configs: - job_name: 'aks-pods' kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_label_app] action: keep regex: .+ remote_write: - url: "https://aps-workspaces.<AWS_REGION>.amazonaws.com/api/v1/remote_write" sigv4: region: "<AWS_REGION>"
  5. 설정을 반영하기 위해 Prometheus Pod 재시작:
  6. kubectl delete pod -l app=prometheus-server -n monitoring

2️⃣ AWS AMP에서 데이터 수집 설정

1. AWS AMP 워크스페이스 생성

AWS 콘솔 또는 CLI를 사용하여 Prometheus 워크스페이스 생성:

aws amp create-workspace --alias aks-prometheus --region <AWS_REGION>
  • 워크스페이스가 생성되면 WorkspaceID가 반환됩니다.
  • AWS AMP 워크스페이스 URL을 기록하세요.

3️⃣ Prometheus가 AWS AMP로 데이터를 전송하도록 인증 설정

AWS의 Prometheus(AWS AMP)로 데이터를 전송하려면 IAM 인증(SigV4) 이 필요합니다.

1. IAM 역할 생성

IAM에서 AWS AMP에 데이터 전송 권한을 부여하는 IAM 역할을 생성합니다.

aws iam create-role --role-name AMP-RemoteWrite-Role --assume-role-policy-document file://trust-policy.json

📌 trust-policy.json 내용 (EKS 또는 AKS에서 사용할 경우):

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "eks.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

2. IAM 정책 생성

aws iam put-role-policy --role-name AMP-RemoteWrite-Role --policy-name AMP-Policy --policy-document file://amp-policy.json

📌 amp-policy.json 내용:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "aps:RemoteWrite"
      ],
      "Resource": "*"
    }
  ]
}

4️⃣ AWS SigV4 Proxy를 사용하여 인증 설정 (AKS에서 실행할 때 필요)

Prometheus는 AWS SigV4 인증이 필요하기 때문에, AWS SigV4 프록시를 사용해야 합니다.

1. SigV4 프록시 배포

kubectl apply -f https://raw.githubusercontent.com/awslabs/amazon-eks-observability-demo/main/sigv4-proxy/deployment.yaml

2. remote_write 설정에 프록시 추가

위 프록시가 실행되면 prometheus.yml의 remote_write 설정을 다음과 같이 변경합니다.

remote_write:
  - url: "http://sigv4-proxy.monitoring.svc.cluster.local:8080/api/v1/remote_write"
    sigv4:
      region: "<AWS_REGION>"

5️⃣ AWS AMP에서 데이터 확인

1. AWS 콘솔에서 확인

  1. AWS 콘솔 → "Amazon Managed Service for Prometheus" → "워크스페이스" 이동
  2. "Query & Graph"에서 데이터가 수집되는지 확인

2. Grafana에서 AWS AMP 연결

Grafana에서 AWS AMP 데이터를 시각화하려면:
1. "Data Sources"에서 "Prometheus" 추가
2. URL: https://aps-workspaces.<AWS_REGION>.amazonaws.com/api/v1/query
3. "SigV4 Authentication"을 활성화하고, IAM Role 설정


✅ 최종 정리

1. AKS에서 Prometheus를 실행하여 Pod 메트릭 수집

  • Helm으로 Prometheus 설치
  • prometheus.yml을 수정하여 AWS AMP로 원격 쓰기 설정

2. AWS AMP에서 Prometheus 워크스페이스 생성

  • AWS AMP에서 Prometheus 엔드포인트 확인
  • IAM 역할을 생성하여 AWS에 인증

3. SigV4 인증 프록시를 사용하여 AWS AMP로 메트릭 전송

  • remote_write에 AWS SigV4 프록시 사용

4. AWS AMP에서 데이터 확인 후 Grafana에서 시각화

  • AWS AMP의 "Query & Graph"에서 데이터 확인
  • Grafana에서 AWS AMP를 데이터 소스로 추가

 이제 Azure AKS의 Prometheus 메트릭을 AWS AMP에서 수집하고 시각화할 수 있습니다! 🚀

반응형