파드의 서비스 품질(QoS) 구성하기

파드의 서비스 품질(QoS) 구성하기 (Configure Quality of Service for Pods)

이 페이지는 특정 QoS(Quality of Service, 서비스 품질) 클래스가 할당되도록 파드를 구성하는 방법을 보여 줘요. 쿠버네티스는 노드 리소스가 초과될 때 파드를 축출(evict)할지 결정하는 데 QoS 클래스를 사용해요.

쿠버네티스는 파드를 만들 때 그 파드에 다음 QoS 클래스 중 하나를 할당해요.

  • Guaranteed
  • Burstable
  • BestEffort

출처: 문서

본문

참고:

시작하기 전에

쿠버네티스 클러스터가 필요하고, kubectl 명령줄 도구가 클러스터와 통신하도록 설정돼 있어야 해요. 이 튜토리얼은 제어 플레인 호스트 역할을 하지 않는 노드가 최소 두 개 있는 클러스터에서 실행하는 것을 권장해요. 아직 클러스터가 없다면 minikube를 사용하거나 다음 쿠버네티스 플레이그라운드 중 하나를 사용해 만들 수 있어요.

  • iximiuz Labs
  • Killercoda
  • KodeKloud

네임스페이스를 만들고 삭제할 수 있어야 해요.

네임스페이스 만들기

이 연습에서 만드는 리소스가 클러스터의 나머지와 격리되도록 네임스페이스를 만들어요.

kubectl create namespace qos-example

QoS 클래스 Guaranteed가 할당되는 파드 만들기

파드가 Guaranteed QoS 클래스를 받으려면:

  • 파드의 모든 컨테이너가 메모리 한도와 메모리 요청을 가져야 해요.
  • 파드의 모든 컨테이너에 대해 메모리 한도가 메모리 요청과 같아야 해요.
  • 파드의 모든 컨테이너가 CPU 한도와 CPU 요청을 가져야 해요.
  • 파드의 모든 컨테이너에 대해 CPU 한도가 CPU 요청과 같아야 해요.

이 제한은 init 컨테이너와 애플리케이션 컨테이너에 동일하게 적용돼요. 임시 컨테이너는 리소스를 정의할 수 없으므로 이 제한이 적용되지 않아요.

컨테이너가 하나인 파드의 매니페스트는 다음과 같아요. 컨테이너에는 200 MiB로 같은 메모리 한도와 메모리 요청이 있고, 700 milliCPU로 같은 CPU 한도와 CPU 요청이 있어요.

apiVersion: v1
kind: Pod
metadata:
  name: qos-demo
  namespace: qos-example
spec:
  containers:
  - name: qos-demo-ctr
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "700m"
      requests:
        memory: "200Mi"
        cpu: "700m"

파드를 만들어요.

kubectl apply -f https://k8s.io/examples/pods/qos/qos-pod.yaml --namespace=qos-example

파드에 대한 상세 정보를 확인해요.

kubectl get pod qos-demo --namespace=qos-example --output=yaml

출력은 쿠버네티스가 파드에 Guaranteed QoS 클래스를 부여했음을 보여 줘요. 출력은 또한 파드 컨테이너에 메모리 한도와 일치하는 메모리 요청이 있고, CPU 한도와 일치하는 CPU 요청이 있음을 확인해 줘요.

spec:
  containers:
    ...
    resources:
      limits:
        cpu: 700m
        memory: 200Mi
      requests:
        cpu: 700m
        memory: 200Mi
    ...
status:
  qosClass: Guaranteed

참고:

정리하기

파드를 삭제하세요.

kubectl delete pod qos-demo --namespace=qos-example

QoS 클래스 Burstable이 할당되는 파드 만들기

파드가 Burstable QoS 클래스를 받는 경우는 다음과 같아요.

  • 파드가 Guaranteed QoS 클래스의 기준을 충족하지 않음.
  • 파드의 컨테이너 중 하나 이상이 메모리 또는 CPU 요청·한도를 가짐.

컨테이너가 하나인 파드의 매니페스트는 다음과 같아요. 컨테이너에는 200 MiB 메모리 한도와 100 MiB 메모리 요청이 있어요.

apiVersion: v1
kind: Pod
metadata:
  name: qos-demo-2
  namespace: qos-example
spec:
  containers:
  - name: qos-demo-2-ctr
    image: nginx
    resources:
      limits:
        memory: "200Mi"
      requests:
        memory: "100Mi"

파드를 만들어요.

kubectl apply -f https://k8s.io/examples/pods/qos/qos-pod-2.yaml --namespace=qos-example

파드에 대한 상세 정보를 확인해요.

kubectl get pod qos-demo-2 --namespace=qos-example --output=yaml

출력은 쿠버네티스가 파드에 Burstable QoS 클래스를 부여했음을 보여 줘요.

spec:
  containers:
  - image: nginx
    imagePullPolicy: Always
    name: qos-demo-2-ctr
    resources:
      limits:
        memory: 200Mi
      requests:
        memory: 100Mi
  ...
status:
  qosClass: Burstable

정리하기

파드를 삭제하세요.

kubectl delete pod qos-demo-2 --namespace=qos-example

QoS 클래스 BestEffort가 할당되는 파드 만들기

파드가 BestEffort QoS 클래스를 받으려면 파드의 컨테이너가 메모리나 CPU 한도·요청을 전혀 가지면 안 돼요.

컨테이너가 하나인 파드의 매니페스트는 다음과 같아요. 컨테이너에는 메모리나 CPU 한도·요청이 없어요.

apiVersion: v1
kind: Pod
metadata:
  name: qos-demo-3
  namespace: qos-example
spec:
  containers:
  - name: qos-demo-3-ctr
    image: nginx

파드를 만들어요.

kubectl apply -f https://k8s.io/examples/pods/qos/qos-pod-3.yaml --namespace=qos-example

파드에 대한 상세 정보를 확인해요.

kubectl get pod qos-demo-3 --namespace=qos-example --output=yaml

출력은 쿠버네티스가 파드에 BestEffort QoS 클래스를 부여했음을 보여 줘요.

spec:
  containers:
    ...
    resources: {}
  ...
status:
  qosClass: BestEffort

정리하기

파드를 삭제하세요.

kubectl delete pod qos-demo-3 --namespace=qos-example

컨테이너가 두 개인 파드 만들기

컨테이너가 두 개인 파드의 매니페스트는 다음과 같아요. 한 컨테이너는 200 MiB 메모리 요청을 지정하고, 다른 컨테이너는 어떤 요청이나 한도도 지정하지 않아요.

apiVersion: v1
kind: Pod
metadata:
  name: qos-demo-4
  namespace: qos-example
spec:
  containers:

  - name: qos-demo-4-ctr-1
    image: nginx
    resources:
      requests:
        memory: "200Mi"

  - name: qos-demo-4-ctr-2
    image: redis

이 파드는 Burstable QoS 클래스의 기준을 충족한다는 점을 주목하세요. 즉, Guaranteed QoS 클래스의 기준을 충족하지 않고, 컨테이너 중 하나가 메모리 요청을 가지기 때문이에요.

파드를 만들어요.

kubectl apply -f https://k8s.io/examples/pods/qos/qos-pod-4.yaml --namespace=qos-example

파드에 대한 상세 정보를 확인해요.

kubectl get pod qos-demo-4 --namespace=qos-example --output=yaml

출력은 쿠버네티스가 파드에 Burstable QoS 클래스를 부여했음을 보여 줘요.

spec:
  containers:
    ...
    name: qos-demo-4-ctr-1
    resources:
      requests:
        memory: 200Mi
    ...
    name: qos-demo-4-ctr-2
    resources: {}
    ...
status:
  qosClass: Burstable

파드의 QoS 클래스 검색하기

모든 필드를 보는 대신 필요한 필드만 볼 수 있어요.

kubectl --namespace=qos-example get pod qos-demo-4 -o jsonpath='{ .status.qosClass}{"\n"}'
Burstable

정리하기

네임스페이스를 삭제하세요.

kubectl delete namespace qos-example

더 알아보기 (Learn more)

앱 개발자를 위해

클러스터 관리자를 위해