devops/ETC
교차 계정 AMP 설정하기 (EKS Prometheus pods to Amazon Managed Prometheus service in Cross Account)
gepp
2024. 6. 28. 17:02
- 구성
- Cross Account 로 EKS 가 있는 A 계정의 prometheus pod에서 AMP가 있는 B 계정으로 전송
- 선수 조건
- external provisioner 이 kube-system 에 설치되어있어야 합니다.
- prometheus-server Pod (alert manager pod 포함) 가 pvc 를 생성하므로, 결합할 수 있는 unbound pv와 storage class가 존재해야 합니다.
- Helm 으로 EKS 클러스터 prometheus 네임스페이스에 프로메테우스 설치
- 헬름 설치:
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
- 리포지토리 추가 :
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
- 헬름 리포로 설치:
helm install prometheus prometheus-community/prometheus -n prometheus --create-namespace --version 25.21.0
- prometheus-server에 아래와 같은 iam 역할 추가:
한 계정에 AMP, EKS가 존재할때
remote_write:
- queue_config:
capacity: 2500
max_samples_per_send: 1000
max_shards: 200
sigv4:
region: <region>
role_arn: arn:aws:iam::<account id>:role/<AMP iam role>
url: https://aps-workspaces.<region>.amazonaws.com/workspaces/<workspace id>/api/v1/remote_write
A 계정에 EKS, B 계정에 AMP 가 존재하는 Cross Account 구성 시
server:
persistentVolume:
accessModes:
- ReadWriteOnce // for an example
enabled: <true or false>
mountPath: <mount path>
size: <storage capacity>
storageClass: <storage class>
remoteWrite:
- queue_config:
capacity: 2500
max_samples_per_send: 1000
max_shards: 200
sigv4:
region: <B ACCOUNT REGION>
role_arn: arn:aws:iam::<B ACCOUNT>:role/<B ACCOUNT AMP ROLE NAME>
url: https://aps-workspaces.<AMP REGION>.amazonaws.com/workspaces/<AMP WORKSPACE ID>/api/v1/remote_write
serviceAccounts:
server:
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::<A ACCOUNT>:role/<A ACCOUNT EKS IRSA ROLE NAME>
name: <SERVICE ACCOUNT NAME>
실제 values.yaml (테스트 환경, A 계정. workspace url은 B계정의 AMP 워크스페이스)
$ cat values.yaml
serviceAccounts:
server:
name: "amp-iamproxy-ingest-service-account"
annotations:
eks.amazonaws.com/role-arn: "<A 계정 EKS IRSA용 IAM Role>"
server:
remote_write:
- queue_config:
capacity: 2500
max_samples_per_send: 1000
max_shards: 200
sigv4:
region: <AMP WORKSPACE REGION>
role_arn: <B 계정 AMP 용 IAM Role>
url: https://aps-workspaces.<REGION>.amazonaws.com/workspaces/<AMP WORKSPACE ID>/api/v1/remote_write
해당 value 로 헬름 업그레이드를 하면 기존 prometheus-server 서비스계정이 사라지고 역할 이름으로 서비스 계정이 자동 생성됩니다.
프로메테우스 로그:
ts=2024-06-27T08:01:38.254Z caller=kubernetes.go:331 level=info component="discovery manager notify" discovery=kubernetes config=config-0 msg="Using pod service account via in-cluster config"
ts=2024-06-27T08:01:38.254Z caller=main.go:1402 level=info msg="Completed loading of configuration file" filename=/etc/config/prometheus.yml totalDuration=7.206003ms db_storage=1.31µs remote_storage=1.439µs web_handler=710ns query_engine=1.139µs scrape=1.467289ms scrape_sd=1.487768ms notify=85.852µs notify_sd=995.151µs rules=204.247µs tracing=6.131µs
A 계정 IAM 권한(A 계정에 EKS, B 계정에 AMP 가 존재하는 Cross Account 구성 시):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": [
"arn:aws:iam::<B 계정 ACCOUNT ID>:role/<B 계정 AMP IAM ROLE NAME"
]
}
]
}
해당 A계정 역할의 신뢰 정책:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::<A Acccount Id>:oidc-provider/oidc.eks.<region>.amazonaws.com/id/<OIDC Id>"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks.<region>.amazonaws.com/id/<OIDC Id>:aud": "sts.amazonaws.com",
"oidc.eks.<region>.amazonaws.com/id/<OIDC Id>:sub": "system:serviceaccount:prometheus:amp-iamproxy-ingest-service-account"
}
}
}
]
}
service account 다음에는 프로메테우스용 네임스페이스, 서비스 계정 이름입니다.
B 계정 IAM 역할 권한(A 계정에 EKS, B 계정에 AMP 가 존재하는 Cross Account 구성 시):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"aps:RemoteWrite",
"aps:QueryMetrics"
],
"Resource": "*"
}
]
}
B 계정 해당 역할의 신뢰정책:
A 계정의 해당 역할을 허용하는 부분이 존재합니다.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<A Account Id>:role/<Role name>"
},
"Action": "sts:AssumeRole"
}
]
}
공식 문서의 설정을 참고하는 것이 좋습니다.
기타 설정 오류 관련:
컨테이너에서 해당 에러 확인시 (컨테이너로 올릴시 uid gid 불일치 문제)
에러 메시지:
panic: Unable to create mmap-ed active query log
goroutine 1 [running]:
github.com/prometheus/prometheus/promql.NewActiveQueryTracker({0x7ffebd0d142b, 0x5}, 0x14, {0x4424b60, 0xc00042e960})
/app/promql/query_logger.go:146 +0x425
ec2 node 에 ssh 하여 아래 명령어 수행시 정상 running
sudo chown -R 65534:65534 /data/prometheus
sudo chmod -R 775 /data/prometheus