반응형
개요
EKS WokerNode를 EC2방식과 Fargate 방식으로 띄울 수 있습니다.
Fargate 방식으로 WorkerNode를 띄울 경우 daemonset pod를 배포할 수 가 없습니다.
daemonset pod를 배포하지 못하면 일어나는 일
- prometheus에서 데이터 수집용인 node-exporter를 배포할 수 가 없습니다.
- 로그 수집 fluent-bit를 배포할 수 가 없습니다.
- 등
1. Fargate에서 로깅하는 방법
메뉴얼 : https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/fargate-logging.html
- Fargate 용 fluent-bit 설치해서 로그를 수집할 수 있습니다.
- fluent-bit container를 사이드카로 배포는 되지 않지만, AWS에서 백그라운드에서 fluentbit를 실행되도록 설정할 수 있습니다.
- fluent-bit container 방식으로 배포되는 것이 아니라서, 기능(옵션) 제한이 있습니다.
- fluent-bit에서 output 지정 가능한 서비스
- CloudWatch
- AWS OpenSearch Service
- Kinesis Data Firehose
2. fluent-bit 설치
fluent-bit 설정이 완료되면 Fargate pod를 재배포해야합니다.
- namespace 배포
kind: Namespace
apiVersion: v1
metadata:
name: aws-observability
labels:
aws-observability: enabled
- ConfigMap 배포
kind: ConfigMap
apiVersion: v1
metadata:
name: aws-logging
namespace: aws-observability
data:
flb_log_cw: "false" # Set to true to ship Fluent Bit process logs to CloudWatch.
filters.conf: |
[FILTER]
Name parser
Match *
Key_name log
Parser crio
[FILTER]
Name kubernetes
Match kube.*
Merge_Log On
Keep_Log Off
Buffer_Size 0
Kube_Meta_Cache_TTL 300s
output.conf: |
[OUTPUT]
Name cloudwatch_logs
Match kube.*
region region-code # ap-northeast-2 수정 필요
log_group_name my-logs # CloudWatch에 생성할 로그 그룹 이름
log_stream_prefix from-fluent-bit-
log_retention_days 60
auto_create_group true
parsers.conf: |
[PARSER]
Name crio
Format Regex
Regex ^(?<time>[^ ]+) (?<stream>stdout|stderr) (?<logtag>P|F) (?<log>.*)$
Time_Key time
Time_Format %Y-%m-%dT%H:%M:%S.%L%z
- IAM 정책 배포
# IAM Policy 다운로드
curl -O https://raw.githubusercontent.com/aws-samples/amazon-eks-fluent-logging-examples/mainline/examples/fargate/cloudwatchlogs/permissions.json
# IAM Policy 생성
aws iam create-policy --policy-name eks-fargate-logging-policy --policy-document file://permissions.json
- IAM Policy Attach 연결
# IAM ROLE 생성 방법
aws iam attach-role-policy \
--policy-arn arn:aws:iam::111122223333:policy/eks-fargate-logging-policy \
--role-name AmazonEKSFargatePodExecutionRole
# 미리 생성한 Fargate 프로필에 등록된 Role에 Policy 연결
aws iam attach-role-policy \
--policy-arn arn:aws:iam::111122223333:policy/eks-fargate-logging-policy \
--role-name "Fargate 프로필에 등록된 Role"
3. CloudWatch 로그 수집 확인
- CloudWatch 로그그룹 확인
- Logs Insights 로그 필터링
- https://ap-northeast-2.console.aws.amazon.com/cloudwatch/home?region=ap-northeast-2#logsV2:logs-insights
- 1 : fluent-bit에서 생성한 로그 그룹 선택
- 2 : 로그를 필터링할 query 입력
- 쿼리 실행
4. Example 쿼리
대소문자 구분안함
(?i) : 대소문자 구분안함
filter @message like /(?i)text 검색할 내용 입력/
ex) filter @message like /(?i)"namespace_name":"dw"/
error 로그 개수
filter @message like /(?i)error/
| stats count(*) as test
5. Grafana Dashboard
- import : 14109
- Data source : cloudWatch 선택
- Region : 리전 선택
- CloudWatch Logs : 선택
- Log Groups : fluent-bit에서 생성한 log group 선택
- filter @log like : "log group" 입력
- filter @message like /(?!)$search : Search Variables에 있는 내용으로 검색
6. Grafana Alert
- Data source : cloudwatch 선택
- Region : 리전 선택
- CloudWatch Logs : 선택
- Log Groups : fluent-bit에서 생성한 log group 선택
- 쿼리 : 대소문자 구분하지 않는 "error" 로그를 숫자로 표시
- filter @message like /(?i)error/ |
stats count(*) as test
- filter @message like /(?i)error/ |
- B : Classic_conditions 선택
- WHEN : last
- OF : A
- IS ABOVE : 로그 개수가 0개 이상이면 알람 발생
알람이 발생하면 Grafana URL 출력되도록 선택
- 시간 : now-5m
- 검색 : error 로그 필터링
반응형
'모니터링 > OpenTelemetry' 카테고리의 다른 글
[OpenTelemetry] Logs 수집 (0) | 2025.05.26 |
---|---|
[Lambda] 업무시간 외 Fargate Stop/Start (0) | 2025.04.16 |
[ Fargate ] Adot-collector 설치 (fargate 메트릭,로그) (0) | 2025.02.26 |
[OpenTelemetry] 설치 (0) | 2023.09.07 |