본문 바로가기
Observability/Logs

[Fluent-Bit] Too many open files

by dev_ss 2023. 11. 30.

사내 프로젝트로 Fluent-Bit을 K8S환경 내 Side-car방식으로 Elasticsearch에 로그 적재를 할 때, 발생했던 문제에 관하여 다루는 자료이다.

 

개요 :

프로젝트 내 Microservice의 개수만큼 Deployment를 생성했었는데, 해당 Deployment에는 하나의 애플리케이션 서버 컨테이너와, 해당 애플리케이션 로그를 수집하는 Fluent-Bit 컨테이너(총 2개의 컨테이너)가 하나의 파드 안에 배포되는 형식으로 생성하였다.

 

Fluent-Bit : https://docs.fluentbit.io/manual/about/what-is-fluent-bit

 

What is Fluent Bit? - Fluent Bit: Official Manual

Rather than serving as a drop-in replacement, Fluent Bit enhances the observability strategy for your infrastructure by adapting and optimizing your existing logging layer, as well as metrics and traces processing. Furthermore, Fluent Bit supports a vendor

docs.fluentbit.io

 

 

초반에는 특이 사항이 없었으나 Deployment를 일정 개수 이상 생성하니, 이후 생성되는 파드 내에서 Fluent-Bit 컨테이너만 죽는 현상이 발생하였다.

[ K9S로 확인한 Pod 상태 ]

 

 

그리하여 Fluent-Bit 내부의 로그를 확인하니 아래와 같은 데이터를 볼 수 있었다.

[ 해당 Fluent-Bit 로그]

 

제목에서 볼 수 있는 것처럼, "Too many open files"라는 에러로 컨테이너가 죽는 것이었다.

 

이는 로그를 수집하기 위해 생성된 특정 인스턴스가 너무 많다는 것이었고, 그 제한으로 인하여 컨테이너 생성에 실패하게 된 것이다.

 

아래는 위 에러와 관련된 깃허브 주소이다.

https://github.com/fluent/fluent-bit/issues/1777

 

in_tail plugin randomly fails with "too many open files" and errno=24 - unless switched from inotify to stat tail · Issue #1777

Bug Report Describe the bug in_tail plugin randomly fails with "too many open files" and errno=24 - unless switched from inotify to stat tail To Reproduce Example log message if applicable: [TIMEST...

github.com

 

해결 방법 :

방법은 생각보다 간단했다.

 

아래 두 개의 파일을 확인하고 부족한 제한사항을 늘려주는 것이었다.

# max_user_watches 확인
cat /proc/sys/fs/inotify/max_user_watches

# max_user_instances 확인
cat /proc/sys/fs/inotify/max_user_instances

 

 

글쓴이는, 위 두 가지 파일에서 max_user_instances가 128로 제한되어 있었고, 이를 늘려주면서 문제는 해결됐다.

# 제한 instance 수 상향
sudo sysctl fs.inotify.max_user_instances=1024
sudo sysctl -p

# 영구 적용 시
# /etc/sysctl.conf에서 fs.inotify.max_user_instances을 수정

 

+ 해당 에러는 위 설정을 통한 트러블 슈팅의 자료가 많이 나왔으나, sysctl 영역을 수정하며 생기는 사이드 이펙트가 확인되지 않았기에, 관련 자료를 좀 더 찾아봐야 할 것 같다.

반응형