내용으로 건너뛰기

Amazon EKS에서 AWS Fargate 포드에 대한 nofile 및 nproc 제한을 늘리려면 어떻게 해야 합니까?

5분 분량
0

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 포드를 실행하려면 다음 단계를 완료하십시오.

  1. Fargate 포드 실행 역할을 생성합니다.
  2. 클러스터의 Fargate 프로필을 생성합니다.
  3. coreDNS를 업데이트합니다.

자세한 내용은 Amazon EKS를 사용하여 AWS Fargate 시작하기를 참조하십시오.

bash 명령 사용

bash 명령을 사용하여 nofile 및 nproc 제한을 늘리려면 다음 단계를 완료하십시오.

  1. 다음과 같은 샘플 포드 매니페스트를 실행합니다.
    참고: 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
  2. 위의 매니페스트를 적용하여 Fargate 네임스페이스에서 새 포드를 생성합니다.
    참고: example-file-name을 이전 포드 매니페스트의 파일 이름으로 바꾸십시오.

    kubectl apply -f example-file-name
  3. 포드가 실행 중인 상태이면 다음 명령을 실행하여 새로운 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 제한을 늘리려면 다음 단계를 완료하십시오.

  1. 다음과 같은 샘플 포드 매니페스트를 실행합니다.
    참고: 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
  2. 포드가 실행 중인 상태이면 다음 명령을 실행하여 새로운 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 제한을 늘리려면 다음 단계를 완료하십시오.

  1. 다음과 같은 샘플 포드 매니페스트를 실행합니다.
    참고: 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
  2. 포드가 실행 중인 상태이면 다음 명령을 실행하여 새로운 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년 전