Amazon EKS の AWS Fargate ポッドの nofile と nproc の制限を引き上げる方法を教えてください。
Amazon Elastic Kubernetes Service (Amazon EKS) で、AWS Fargate ポッドの nofile と nproc の制限を引き上げたいです。
簡単な説明
Fargate でアプリケーションを実行すると、Fargate ポッドの ulimit 設定に関連する次のいずれかのエラーが表示される場合があります。
- 開いているファイルが多すぎます。
- スレッド不足エラーまたはランタイム: 新しい OS スレッドを作成できませんでした。
- プロセスを作成するためのリソースがありません。
nofile と nproc の制限を引き上げるには、bash コマンド、sh コマンド、または Init コンテナのいずれかを使用します。
注: Fargate ポッドの ulimit 設定は構成できません。デフォルトの nofile と nproc のソフトリミットは 1024 で、ハードリミットは 65535 です。詳細については、「AWS Fargate の考慮事項」を参照してください。
解決策
Amazon EKS で Fargate ポッドを起動するには、次の手順を実行します。
- Fargate ポッドの実行ロールを作成します。
- クラスターに Fargate プロファイルを作成します。
- coreDNS を更新します。
詳細については、「Amazon EKS を使用して AWS Fargate を開始する方法」を参照してください。
bash コマンドを使用する
bash コマンドを使用して nofile と nproc の制限を引き上げるには、次の手順を実行します。
-
以下のサンプルポッドマニフェストを実行します。
注: example-nofile-limit と example-nofile-limit は、nofile と nproc 用の新しい制限値に置き換えます。有効な範囲は 1024 から 65535 です。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 名前空間に新しいポッドを作成します。
注: example-file-name は、上記のポッドマニフェストのファイル名に置き換えます。kubectl apply -f example-file-name -
ポッドが実行状態になったら、次のコマンドを実行して新しい 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 の制限を引き上げるには、次の手順を実行します。
-
以下のサンプルポッドマニフェストを実行します。
注: example-nofile-limit と example-nofile-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 -
ポッドが実行状態になったら、次のコマンドを実行して新しい 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
Init コンテナを使用する
メインコンテナで sh コマンドを実行したくない場合は、Init コンテナを使用して同じコマンドを実行します。詳細については、Kubernetes のウェブサイトで「Init コンテナ」を参照してください。
Init コンテナを使用して nofile と nproc の制限を引き上げるには、次の手順を実行します。
-
以下のサンプルポッドマニフェストを実行します。
注: example-nofile-limit と example-nofile-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 -
ポッドが実行状態になったら、次のコマンドを実行して新しい 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
- トピック
- Containers
- 言語
- 日本語

関連するコンテンツ
AWS公式更新しました 2年前