LoginSignup
25
12

More than 3 years have passed since last update.

EKS 上のコンテナでファイル監視数の上限を増やす

Last updated at Posted at 2019-05-22

EKS 上のコンテナで Rails アプリケーションを動かしているのですが、
ある日コンテナ内で rails console が立ち上がらなくなったので調査しました。

$ rails c
FATAL: Listen error: unable to monitor directories for changes.
Visit https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers for info on how to fix this.

https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers を見ると
fs.inotify.max_user_watches の上限を変えてあげれば問題なさそうです。

現在の設定を確認します。

$ cat /proc/sys/fs/inotify/max_user_watches
8192

参考サイトの通りに変更できるか試してみます。

$ echo fs.inotify.max_user_watches=524288 | tee -a /etc/sysctl.conf && sysctl -p
fs.inotify.max_user_watches=524288
sysctl: setting key "fs.inotify.max_user_watches": Read-only file system

ははーん。まぁ、なんとなく分かってたけど。。。
どうすればええんや。

これはNG

Docker コンテナなので、最終的には、Image で設定したくなりますよね。

FROM ruby:2.6.2-slim-stretch
...
RUN echo "fs.inotify.max_user_watches=524288" | tee -a /etc/sysctl.conf
...

で、build は通るものの、実際の値は変わらず。

これはOK

それらしき、ありがたい記事を見つけました
「DockerはKernel共有する」とよく聞くけどそれによって何が起きるか調べてみた#記事が長いので先に結論

特にカーネルパラメータで上限設定されているものが共有されていると、コンテナ・ホスト間でリソースの奪い合いが起きます

つまり、EC2 の設定をコンテナで引き継いでいるのでは。
EKSのノード(EC2)内で設定してみます。

$ echo "fs.inotify.max_user_watches = 524288" >> /etc/sysctl.conf && sysctl -p

コンテナ内で再確認

$ cat /proc/sys/fs/inotify/max_user_watches
524288
$ rails c
Running via Spring preloader in process 194
Loading staging environment (Rails 5.2.3)
irb(main):001:0>

めでたしめでたし。

[2019-05-24 追記]
GKE でも同様なので、GCE から SSH して設定変えて上げれば大丈夫です
Compute_Engine_-_bananaci_-_Google_Cloud_Platform

25
12
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
12