Kubernetes

Fluent Bit - Kubernetes Filter를 사용하여 POD 로그 제외하기

DevelopC 2023. 7. 14. 11:25
728x90

Fluent Bit - Kubernetes Filter를 사용하여 POD 로그 제외하기

kubernetes에서 fluent-bit를 사용하여 로그를 CloudWatch 또는 다른데로 전송할때 특정 POD로그를 제외하는 방법입니다. fluent-bit의 kubernetes filter가 제공해주는 기능이고, fluent-bit가 지정된 로그파일을 읽지만 output 설정을 통한 전송은 하지 않습니다.

 

Fluent Bit 설정

아래의 예제는 output을 AWS cloudwatch로 설정하였습니다. kubernetes filter에서 K8S-Logging.Exclude 설정은 On으로 설정해야합니다.

[SERVICE]
    Flush                     5
    Log_Level                 info
    Daemon                    off
    HTTP_Server               on
    HTTP_Listen               0.0.0.0
    HTTP_Port                 2020
    storage.path              /var/fluent-bit/state/flb-storage/
    storage.sync              normal
    storage.checksum          off
    storage.backlog.mem_limit 5M
    
[INPUT]
    Name                tail
    Tag                 application.*
    Path                /var/log/containers/*.log
    DB                  /var/fluent-bit/state/flb_container.db
    Mem_Buf_Limit       100MB
    Skip_Long_Lines     On
    Refresh_Interval    10
    Rotate_Wait         30
    storage.type        filesystem
    Read_from_Head      off

[FILTER]
    Name                kubernetes
    Match               application.*
    Kube_URL            https://kubernetes.default.svc.cluster.local:443
    Kube_Tag_Prefix     application.var.log.containers.
    Merge_Log           On
    Merge_Log_Key       log_processed
    K8S-Logging.Parser  On
    # K8S-Logging.Exclude 설정을 On으로 해야함
    K8S-Logging.Exclude On
    Labels              Off
    Annotations         Off
    Use_Kubelet         On
    Kubelet_Port        10250
    Buffer_Size         0

[OUTPUT]
    Name                cloudwatch_logs
    Match               application.*
    region              ap-northeast-2
    log_group_name      /cluster/application
    auto_create_group   true
    Retry_Limit         3

POD Annotation 설정으로 로그 수집 제외하기

fluentbit.io/exclude annotation을 true로 설정하면 kubernetes filter로 인해서 aws cloudwatch로 로그 전송이 안되는걸 확인할 수 있습니다.

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: default
  annotations:
    # exclude annotation
    fluentbit.io/exclude: "true"
spec:
  containers:
  - name: nginx
    image: nginx:1.25
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 80

참고

 

Kubernetes - Fluent Bit: Official Manual

So at this point the filter is able to gather the values of pod_name and namespace, with that information it will check in the local cache (internal hash table) if some metadata for that key pair exists, if so, it will enrich the record with the metadata v

docs.fluentbit.io

 

728x90

'Kubernetes' 카테고리의 다른 글

Tekton CI/CD 활용한 지속적 통합 및 배포  (0) 2023.07.17
Kubernetes shareProcessNamespace  (0) 2023.03.30
Kubernetes podAntiAffinity  (0) 2023.03.23
Kubernetes Headless Service  (0) 2023.03.21
AWS Fluent Bit error 수정  (0) 2023.03.14