주녁, DevNote
article thumbnail

1. 개요

쿠버네티스를 사용하면서 마주치는 다양한 상황이 발생한다.

이에 따라 적용할 수 있는 여러가지 패턴과 대응할 수 있는 옵션들을 알아본다.

2. 목표

  • 쿠버네티스 Node의 자원에 따라 발생할 수 있는 다양한 상황을 알아본다.
  • Node가 자원의 압박을 받을 때 사용할 수 있는 리소스와 옵션들을 학습한다.

3. 여정

3.1. Node가 사용하는 컴퓨팅 자원 2가지

  • 압축 불가능 자원 : CPU, 네트워크 대역폭 → 많아지면 병목 현상이 발생한다.
  • 압축 불가능 자원 : 메모리 → 많아지면 컨테이너가 죽는다

3.2. QoS(Quality of Service)

  • kubelet이 Node의 안정성을 유지하기 위해 사용 가능한 컴퓨팅 자원을 조절하는 기능
  • Best-Effort(최선)
    • request, limit 자원 요구 사항을 가지고 있지 않은 Pod
    • 자원이 부족할 때 가장 먼저 죽는다.
  • Burstable(확장 가능)
    • request < limit인 자원 요구 사항을 가진 Pod
    • limit까지 더 많은 자원을 소비하려고 한다.
    • Best-Effort Pod가 없다면 죽을 확률이 높다.
  • Guaranteed(보장)
    • request = limit인 자원 요구 사항을 가진 Pod
    • 가장 우선순위가 높아서 가장 나중에 죽는다.

3.3. Priority Class

  • kubelet이 Pod를 배치(Scheduler)하거나 축출(evict)할 때 고려하는 우선순위 기능
  • Node가 Pod 배치를 고려할 때 (Schedule)
    • kubelet은 QoS를 먼저 고려하고, Priority Class를 고려한다.
  • Node가 축출할 때 (Evict)
    • kubelet은 QoS를 완전 무시하고, Priority Class를 고려한다.
    • 따라서, Priority Class가 높은 Pod가 먼저 배치된다.
    • 자원이 충분하지 않다면, 가장 우선 순위가 낮은 Pod를 제거한다.
<csharp />
# PriorityClass 정의 apiVersion: scheduling.k8s.io/v1 kind: PriorityClass metadata: name: high-priority-nonpreempting value: 1000000 # 우선순위 preemptionPolicy: Never # 선점 가능 여부 (Never, IfNotPresent, Always) globalDefault: false # 클러스터 전체 기본값 여부 description: "This priority class will not cause other pods to be preempted."
<csharp />
# PriorityClass를 사용한 Pod 정의 apiVersion: v1 kind: Pod metadata: name: nginx labels: env: test spec: containers: - name: nginx image: nginx imagePullPolicy: IfNotPresent priorityClassName: high-priority-nonpreempting

3.4. Resource Quota

  • namaspace 안에서 집계된 자원 소비를 제한하기 위한 제약 조건
  • 제한 가능한 리소스 종류
    • Compute Resource Quota
    • Storage Resource Quota
    • Object Count Quota
  • Quota Scopes
    • 제약을 적용할 범위를 Pod Status, QoS, Affinity에 따라 적용할 수 있다.

출처 : 쿠버네티스 공식문서

 

<csharp />
# ResourceQuota 예시 apiVersion: v1 kind: List items: - apiVersion: v1 kind: ResourceQuota metadata: name: pods-high spec: hard: cpu: "1000" memory: 200Gi pods: "10" scopeSelector: matchExpressions: - operator : In scopeName: PriorityClass values: ["high"] - apiVersion: v1 kind: ResourceQuota metadata: name: pods-medium spec: hard: cpu: "10" memory: 20Gi pods: "10" scopeSelector: matchExpressions: - operator : In scopeName: PriorityClass values: ["medium"] - apiVersion: v1 kind: ResourceQuota metadata: name: pods-low spec: hard: cpu: "5" memory: 10Gi pods: "10" scopeSelector: matchExpressions: - operator : In scopeName: PriorityClass values: ["low"]

 

3.5. Limit Range

  • 각 자원 종류마다 최대 자원을 설정할 수 있는 리소스
<csharp />
apiVersion: v1 kind: LimitRange metadata: name: cpu-resource-constraint spec: limits: - default: # this section defines default limits cpu: 500m defaultRequest: # this section defines default requests cpu: 500m max: # max and min define the limit range cpu: "1" min: cpu: 100m type: Container

4.  


참고자료

https://kubernetes.io/ko/docs/tasks/configure-pod-container/quality-service-pod/

https://kubernetes.io/ko/docs/concepts/scheduling-eviction/pod-priority-preemption/

https://kubernetes.io/ko/docs/concepts/policy/resource-quotas/

https://kubernetes.io/ko/docs/concepts/policy/limit-range/

profile

주녁, DevNote

@junwork

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!