Complete a 3 Question Survey and Earn a re:Post Badge
Help improve AWS Support Official channel in re:Post and share your experience - complete a quick three-question survey to earn a re:Post badge!
如何提高 Amazon EKS 中 AWS Fargate 容器组 (pod) 的 nofile 和 nproc 限制?
我想提高 Amazon Elastic Kubernetes Service (Amazon EKS) 中 AWS Fargate 容器组 (pod) 的 nofile 和 nproc 限制。
简短描述
在 Fargate 上运行应用程序时,您可能会收到以下与 Fargate 容器组 (pod) 上的 ulimit 设置相关的错误之一:
- 打开的文件过多。
- 线程不足错误或运行时:无法创建新的操作系统线程。
- 没有可用于创建流程的资源。
要增加 nofile 和 nproc 限制,请使用 bash 命令、sh 命令或初始化容器。
**注意:**您无法为 Fargate 容器组 (pod) 配置 ulimit 设置。默认的 nofile 和 nproc 软限制为 1024,硬限制为 65535。有关详细信息,请参阅 AWS Fargate 注意事项。
解决方法
要在 Amazon EKS 上启动 Fargate 容器组 (pod),请完成以下步骤:
- 创建 Fargate 容器组 (pod) 执行角色。
- 为您的集群创建 Fargate 配置文件。
- 更新 CoreDNS。
有关详细信息,请参阅通过 Amazon EKS 开始使用 AWS Fargate。
使用 bash 命令
要使用 bash 命令提高 nofile 和 nproc 限制,请完成以下步骤:
-
运行以下示例容器组 (pod) 清单:
**注意:**将 example-nofile-limit 和 example-nproc-limit 替换为介于 1024 到 65535 之间的新 nofile 和 nproc 限制。apiVersion: v1 kind: Pod metadata: name: ubuntu namespace: fargate labels: app: ubuntu spec: containers: - image: ubuntu:18.04 command: ["/bin/bash", "-c", "echo 'ulimit -Sn example-nofile-limit' >> /root/.bashrc && echo 'ulimit -Su example-nproc-limit' >> /root/.bashrc && sleep 100"] imagePullPolicy: IfNotPresent name: ubuntu-test restartPolicy: Always
-
应用前面的清单以在 Fargate 命名空间中创建新的容器组 (pod):
**注意:**将 example-file-name 替换为前面的容器组 (pod) 清单的文件名。kubectl apply -f example-file-name
-
当容器组 (pod) 处于运行状态时,运行以下命令以验证新的 nofile 和 nproc 限制:
~ % kubectl exec -it ubuntu -n fargate -- /bin/bash
输出示例:
root@ubuntu:/# ulimit -a core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 30446 max locked memory (kbytes, -l) unlimited max memory size (kbytes, -m) unlimited open files (-n) example-nofile-limit pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) example-nproc-limit virtual memory (kbytes, -v) unlimited file locks (-x) unlimited root@ubuntu:/# ulimit -Sn example-nofile-limit root@ubuntu:/# ulimit -Su example-nproc-limit
使用 sh 命令
要使用 sh 命令提高 nofile 和 nproc 限制,请完成以下步骤:
-
运行以下示例容器组 (pod) 清单:
**注意:**将 example-nofile-limit 和 example-nproc-limit 替换为新的 nofile 和 nproc 限制。apiVersion: v1 kind: Pod metadata: name: alpine namespace: fargate labels: app: alpine spec: containers: - image: alpine:latest command: ["sh", "-c", "echo 'ulimit -Sn example-nofile-limit' >> /etc/.shrc && echo 'ulimit -Su example-nproc-limit' >> /etc/.shrc && sleep 100"] imagePullPolicy: IfNotPresent name: alpine env: - name: ENV value: /etc/.shrc restartPolicy: Always
-
当容器组 (pod) 处于运行状态时,运行以下命令以验证新的 nofile 和 nproc 限制:
~ % kubectl exec -it alpine -n fargate -- sh
输出示例:
/ # ulimit -a core file size (blocks) (-c) unlimited data seg size (kb) (-d) unlimited scheduling priority (-e) 0 file size (blocks) (-f) unlimited pending signals (-i) 30446 max locked memory (kb) (-l) unlimited max memory size (kb) (-m) unlimited open files (-n) example-nofile-limit POSIX message queues (bytes) (-q) 819200 real-time priority (-r) 0 stack size (kb) (-s) 10240 cpu time (seconds) (-t) unlimited max user processes (-u) example-nproc-limit virtual memory (kb) (-v) unlimited file locks (-x) unlimited
使用初始化容器
如果您不想在主容器中运行 sh 命令,请使用初始化容器运行相同的命令。有关详细信息,请参阅 Kubernetes 网站上的初始化容器。
要使用初始化容器提高 nofile 和 nproc 限制,请完成以下步骤:
-
运行以下示例容器组 (pod) 清单:
**注意:**将 example-nofile-limit 和 example-nproc-limit 替换为新的 nofile 和 nproc 限制。apiVersion: v1 kind: Pod metadata: name: alpine namespace: fargate labels: app: alpine spec: containers: - name: alpine image: alpine:latest imagePullPolicy: IfNotPresent command: ['sh', '-c', 'echo The app is running! && sleep 3600'] env: - name: ENV value: /etc/.shrc volumeMounts: - name: data mountPath: /etc initContainers: - name: init image: alpine:latest command: ["sh", "-c", "echo 'ulimit -Sn example-nofile-limit' >> /etc/.shrc && echo 'ulimit -Su example-nproc-limit' >> /etc/.shrc && sleep 10"] volumeMounts: - name: data mountPath: /etc volumes: - name: data emptyDir: {} restartPolicy: Always
-
当容器组 (pod) 处于运行状态时,运行以下命令以验证新的 nofile 和 nproc 限制:
~ % kubectl exec -it alpine -n fargate -- sh
输出示例:
~ # env KUBERNETES_SERVICE_PORT=443 KUBERNETES_PORT=tcp://10.100.0.1:443 HOSTNAME=alpine SHLVL=1 HOME=/ ENV=/etc/.shrc ~ # ulimit -a core file size (blocks) (-c) unlimited data seg size (kb) (-d) unlimited scheduling priority (-e) 0 file size (blocks) (-f) unlimited pending signals (-i) 30446 max locked memory (kb) (-l) unlimited max memory size (kb) (-m) unlimited open files (-n) example-nofile-limit POSIX message queues (bytes) (-q) 819200 real-time priority (-r) 0 stack size (kb) (-s) 10240 cpu time (seconds) (-t) unlimited max user processes (-u) example-nproc-limit virtual memory (kb) (-v) unlimited file locks (-x) unlimited

相关内容
- AWS 官方已更新 3 个月前