58. 如何在 Linux 主机上增加 inotify.max_user_watches 和 inotify.max_user_instances 系统
在 Kubernetes 集群中,这种行为常常导致带有上述错误日志的 Pod 失败。本文详细说明了如何检查和提高这些限额。定义了用户可创建的 inotify 资源和文件监视数量的上限。访问Rancher-K8S解决方案博主 :https://blog.csdn.net/lidw2009。如果 Pods 中没有显示变化,您可能需要重启 Pods 或重启主机。Linux 主机 / Kubernetes
Linux Host / Kubernetes Node
Linux 主机 / Kubernetes 节点
The sysctls fs.inotify.max_user_instances and fs.inotify.max_user_watches define the upper limits on the number of inotify resources and file watches a user can create. If these limits are reached, processes may fail with errors such as:
sysctl fs.inotify.max_user_instances 和 fs.inotify.max_user_watches 定义了用户可创建的 inotify 资源和文件监视数量的上限。如果达到这些限制,进程可能会因以下错误而失败:
-
ENOSPC: System limit for number of file watchers reached... -
The configured user limit (128) on the number of inotify instances has been reached -
The default defined inotify instances (128) has been reached
In a Kubernetes cluster, this behavior often results in failing Pods with logs containing the errors above. This article details how to check and increase these limits.
在 Kubernetes 集群中,这种行为常常导致带有上述错误日志的 Pod 失败。本文详细说明了如何检查和提高这些限额。
1. Check current limits 1. 检查电流限制
To check the current inotify user instance limit, run:
要检查当前的 inotify 用户实例限制,请运行:
<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>cat /proc/sys/fs/inotify/max_user_instances</code></span></span></span>
To check the current inotify user watch limit, run:
要检查当前的 inotify 用户观看限制,请运行:
<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>cat /proc/sys/fs/inotify/max_user_watches</code></span></span></span>
2. Update the limits 2. 更新限制
Temporary - Applied immediately, lost on reboot
临时 - 立即应用,重启时丢失
Run the following commands to increase the limits (using 8,192 and 524,288 as examples):
运行以下命令以增加限制(以8,192和524,288为例):
<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>sudo sysctl fs.inotify.max_user_instances=8192
sudo sysctl fs.inotify.max_user_watches=524288</code></span></span></span>
Permanent - Persistent across reboots
永久性——在重启过程中持续存在
Add the following lines to /etc/sysctl.conf (or a dedicated file in /etc/sysctl.d/):
在 /etc/sysctl.conf(或在 /etc/sysctl.d/ 中添加专用文件)添加以下几行:
<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=524288</code></span></span></span>
After saving the file, apply the changes by running:
保存文件后,通过运行以下程序应用更改:
<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>sudo sysctl -p</code></span></span></span>
3. Validate the changes 3. 验证变更
You can verify the updates on the host by re-running the cat commands from Step 1.
你可以通过重新运行第一步的 cat 命令来验证主机上的更新。
To check if the updated values are reflected within a running pod, execute the following:
要检查更新后的值是否反映在运行中的 pod 中,请执行以下操作:
<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>kubectl exec -it -n <pod-namespace> <pod-name> -- cat /proc/sys/fs/inotify/max_user_instances
kubectl exec -it -n <pod-namespace> <pod-name> -- cat /proc/sys/fs/inotify/max_user_watches</code></span></span></span>
If changes are not reflected within the Pods, you may need to restart the Pods or reboot the host.
如果 Pods 中没有显示变化,您可能需要重启 Pods 或重启主机。
访问Rancher-K8S解决方案博主 :https://blog.csdn.net/lidw2009
更多推荐
所有评论(0)