【问题标题】:How to change the file-system watcher limit in Kubernetes (fs.inotify.max_user_watches)如何更改 Kubernetes 中的文件系统观察程序限制 (fs.inotify.max_user_watches)
【发布时间】:2021-11-10 22:08:48
【问题描述】:

我正在使用 pm2 来查看包含我的应用服务器的 NodeJS 程序源代码的目录,该程序在 Kubernetes 集群中运行。

但是,我收到此错误:

ENOSPC: System limit for number of file watchers reached

我搜索了那个错误,找到了这个答案:https://stackoverflow.com/a/55763478

# insert the new value into the system config
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

但是,我尝试在目标 k8s 节点上的 pod 中运行它,它说找不到命令 sudo。如果我删除 sudo,我会收到此错误:

sysctl: setting key "fs.inotify.max_user_watches": Read-only file system

如何将文件系统观察程序限制从 Kubernetes 节点上的 8192 修改为更高的值,例如 524288?

【问题讨论】:

    标签: linux kubernetes inotify


    【解决方案1】:

    我找到了解决方案:使用在集群中每个节点上运行的特权守护程序集,它具有修改fs.inotify.max_user_watches 变量的能力。

    将以下内容添加到您的 Kubernetes 集群中包含的 node-setup-daemon-set.yaml 文件中:

    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: node-setup
      namespace: kube-system
      labels:
        k8s-app: node-setup
    spec:
      selector:
        matchLabels:
          name: node-setup
      template:
        metadata:
          labels:
            name: node-setup
        spec:
          containers:
          - name: node-setup
            image: ubuntu
            command: ["/bin/sh","-c"]
            args: ["/script/node-setup.sh; while true; do echo Sleeping && sleep 3600; done"]
            env:
              - name: PARTITION_NUMBER
                valueFrom:
                  configMapKeyRef:
                    name: node-setup-config
                    key: partition_number
            volumeMounts:
              - name: node-setup-script
                mountPath: /script
              - name: dev
                mountPath: /dev
              - name: etc-lvm
                mountPath: /etc/lvm
            securityContext:
              allowPrivilegeEscalation: true
              privileged: true
          volumes:
            - name: node-setup-script
              configMap:
                name: node-setup-script
                defaultMode: 0755
            - name: dev
              hostPath:
                path: /dev
            - name: etc-lvm
              hostPath:
                path: /etc/lvm
    ---
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: node-setup-config
      namespace: kube-system
    data:
      partition_number: "3"
    ---
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: node-setup-script
      namespace: kube-system
    data:
      node-setup.sh: |
        #!/bin/bash
        set -e
    
        # change the file-watcher max-count on each node to 524288
    
        # insert the new value into the system config
        sysctl -w fs.inotify.max_user_watches=524288
    
        # check that the new value was applied
        cat /proc/sys/fs/inotify/max_user_watches
    

    注意:上面的文件可能会简化很多。 (我基于this guide,并留下了很多简单运行sysctl 命令可能不需要的东西。)如果其他人成功地进一步修剪它,同时确认它仍然有效,请随意制作/建议对我的答案进行这些修改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      相关资源
      最近更新 更多