[Kubernetes] 파일 시스템 갯수 늘리기


서론

On-prmise에서 쿠버네티스를 사용하다보면 파일 시스템 갯수제한(파일을 열수있는 갯수) 때문에 파드를 실행하지 못하는 경우가 생긴다.

데이터베이스도 결국 파일시스템을 사용하여 내용을 유지하고 있듯이 쿠버네티스의 파드도 마찬가지이다.

파일 시스템 갯수제한 오류

오류를 봐보자

{“level”:“info”,“ts”:“2025-04-27T13:21:08Z”,“logger”:“controller-runtime.certwatcher”,“msg”:“Updated current TLS certificate”}                                                                          │
│ F0427 13:21:08.809403       1 config.go:46] config=main.Config{CertFile:“/etc/webhook/certs/tls.crt”, KeyFile:“/etc/webhook/certs/tls.key”} Error: too many open files                                  │
│ stream closed EOF for kubeflow/admission-webhook-deployment-5ff6bc6ddf-tvjjs (admission-webhook)    

위 오류를 보면 Error: too many open files 라고 떠있다.

jj@jj-node3:~$ sudo systemctl restart containerd
Failed to allocate directory watch: Too many open files

이를 해결하기 위해서는 리눅스에서 파일 시스템을 열 수 있는 갯수 제한을 늘려줘야한다.

먼저 열 수 있는 파일 갯수를 확인해보자.

파일을 열 수 있는 갯수는 유저와 루트가 다르다.

  • 루트의 경우
jj@jj-node3:~$ sudo su
[sudo] password for jj:
root@jj-node3:/home/jj# ulimit -n
1024
root@jj-node3:/home/jj# ulimit -Sn
1024
root@jj-node3:/home/jj# ulimit -Hn
  • 사용자의 경우
jj@jj-node3:~$ ulimit -n
65536
jj@jj-node3:~$ ulimit -Sn
65536
jj@jj-node3:~$ ulimit -Hn
65536

이를 바꾸기 위해서 설정을 변경해야 한다.

root@jj-node3:/home/jj# vim /etc/security/limits.conf

Enable ESM Apps to receive additional future security updates.
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#        - chroot - change root to directory (Debian-specific)
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#root            hard    core            100000
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#ftp             -       chroot          /ftp
#@student        -       maxlogins       4

# End of file
root soft nofile 1048576
root hard nofile 1048576
* soft nofile 1048576
* hard nofile 1048576

위 처럼 루트와 사용자에 대한 파일 갯수를 확장 해준다.

$ sudo vim /etc/pam.d/common-session

그리고 맨 아래애 이걸 추가해준다.

session required pam_limits.so

ssh 접속을 해제 했다가 다시 들어가면 변경된걸 볼 수 있다.

jj@jj-node3:~$ sudo su
[sudo] password for jj:
root@jj-node3:/home/jj# ulimit -Hn
1048576
root@jj-node3:/home/jj# ulimit -Sn
1048576
root@jj-node3:/home/jj# ulimit -n
1048576

마지막으로 해줘야하는 설정이 있는데

아래 명령어를 입력해준다

$ sysctl fs.inotify
$ sysctl -w fs.inotify.max_user_instances=8192
$ sysctl -w fs.inotify.max_user_watches=524288

그러나 위 명령어를 입력해주고 재시작하면 반영되지 않으니 vim으로 아래 설정을 열어서 맨 아래에 추가해준다.

$ vim /etc/sysctl.conf

fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=524288