티스토리 뷰

한 개의 쿠버네티스 클러스터에는 다음과 같이 Master 노드를 포함하여 여러개의 Worker 노드로 구성되어 있다. 공식 홈페이지의 구성도는 다음과 같다.

@쿠버네티스 공식문서

 

전체 Cluster의 리소스를 직접적으로 모니터링 하는 것보다는 각각 노드 레벨에서의 할당가능한 자원량을 모니터링하는 것이 정확할 수 있다 . 파드는 자신과 노드의 여러가지 조건에 따라서 특정 노드에 스케쥴링 되기 때문이다. 이때 파드가 고려하는 것은 리소스에 대한 개별 및 총체적 요구 사항, 하드웨어/소프트웨어/정책적 제약, 어피니티(affinity) 및 안티-어피니티(anti-affinity) 명세, 데이터 지역성, 워크로드-간 간섭, 데드라인 등이 있다.

 

Pod 는 Node의 모든 자원을 활용할 수는 없다. Node 는 다음과 같이 4가지로 자원을 분배하고 있기 때문이다. pod는 노드에서 allocatable resources만을 취할 수 있다.

@k8s공홈

 

Node Allocatable은 v1.NodeAPI에서 객체의 일부로 kubectl describe node 명령어로 확인할 수 있다.(사용중인양은 kubectl top node) 당장 중요한것은 그렇다면 pod에게 할당할 수 있는 자원이라고 생각할 수 있지만 나머지도 알아놓을 필요는 있다.

kube-reserved kube system daemon 을 위해 자원 예약
system-reserved OS(운영체제)를 위한 자원 예약
eviction-threshold 노드-압박 축출(kubelet이 노드의 메모리 가용성이 예약된 값 아래로 떨어질 때마다 노드의 자원을 회수하기 위해 파드를 능동적으로 중단시키는 절차)위해 memory 와 ephemeral-storage 을 지원
allocatable 전체 노드자원에서 kube-reserved, system-reserved, eviction-threshold를 뺀 pod에 할당 가능한 자원

각각의 자원은 kubelet 컨피그 파일을 통해서 셋팅될 수 있다. 

 

kube-reserved

Kubelet Flag: --kube-reserved=[cpu=100m][,][memory=100Mi][,][ephemeral-storage=1Gi][,][pid=1000]

kube-reserved는 kubelet, 컨테이너 런타임, 노드 문제 detector 등과 같은 kubernetes 시스템 데몬에 대한 리소스 예약을 위한 것이다. cpu, 메모리 및 임시 저장 장치 외에도 pid를 지정하여 kubernetes 시스템 데몬에 대해 지정된 수의 프로세스 ID를 예약할 수 있다.

Kubelet Flag: --kube-reserved-cgroup=

옵션으로 --kube-reserved-cgroup= 을 주면 kube-daemon의 상위 제어 그룹을 특정할 수 있다.

 

cgroup - cgroup 샌드박스를 관리하기 위해 호스트에서 cgroup 파일 시스템을 직접 조작하는 기본 드라이버
- namespace에 대한 관리, 추적을 위한 역할
systemd - 해당 init 시스템에서 지원하는 리소스에 대한 임시 슬라이스를 사용하여 cgroup 샌드박스를 관리하는 드라이버

쿠버네티스는 cgroupd으로 systemd 를 사용하라고 권고한다. (이유는 나중에 자세히 포스팅할 예정)

 

system-reserved

Kubelet Flag: --system-reserved=[cpu=100m][,][memory=100Mi][,][ephemeral-storage=1Gi][,][pid=1000]

system-reserved는 sshd, udev 등과 같은 OS 시스템 데몬에 대한 리소스 예약을 캡처하기 위한 것이다. 현재 Kubernetes의 포드에는 커널 메모리가 고려되지 않으므로 system-reserved는 커널에 대한 메모리도 예약해야 한다.

옵션으로 --system-reserved-cgroup= 을 주면 os의 상위 제어 그룹을 특정할 수 있다.

 

Eviction Threshold 

Kubelet Flag: --eviction-hard=[memory.available<500Mi]

노드 수준의 메모리 부족은 전체 노드와 노드에서 실행 중인 모든 포드에 영향을 미치는 시스템 OOM(out of memory)으로 이어지기 때문에, 이때 노드는 메모리가 회수될 때까지 일시적으로 오프라인 상태가 될 수 있다. 이를 방지(또는 확률 감소)하기 위해 kubelet은 리소스를 관리한다. Eviction(축출)은 메모리 및 임시 스토리지(ephemeral-storage)에 대해서만 지원된다. --eviction-hard 플래그를 통해 일부 메모리를 예약함으로써 kubelet은 노드의 메모리 가용성이 예약된 값 아래로 떨어질 때마다 파드를 축출하려고 시도한다. 만약 시스템 데몬이 노드에 존재하지 않는 경우엔 포드는 capacity - eviction-hard 이상을 사용할 수 없다.

 

 

Node Allocatable

Kubelet Flag: --enforce-node-allocatable=pods[,][system-reserved][,][kube-reserved]

kubelet은 기본적으로 파드 전체에 'Allocatable'을 적용한다. 모든 포드의 전체 사용량이 'Allocatable'을 초과할 때마다 포드를 축출한다.

 

Example Scenario

Here is an example to illustrate Node Allocatable computation:

  • Node has 32Gi of memory, 16 CPUs and 100Gi of Storage
  • --kube-reserved is set to cpu=1,memory=2Gi,ephemeral-storage=1Gi
  • --system-reserved is set to cpu=500m,memory=1Gi,ephemeral-storage=1Gi
  • --eviction-hard is set to memory.available<500Mi,nodefs.available<10%

Under this scenario, 'Allocatable' will be 14.5 CPUs, 28.5Gi of memory and 88Gi of local storage. Scheduler ensures that the total memory requests across all pods on this node does not exceed 28.5Gi and storage doesn't exceed 88Gi. Kubelet evicts pods whenever the overall memory usage across pods exceeds 28.5Gi, or if overall disk usage exceeds 88Gi If all processes on the node consume as much CPU as they can, pods together cannot consume more than 14.5 CPUs.

If kube-reserved and/or system-reserved is not enforced and system daemons exceed their reservation, kubelet evicts pods whenever the overall node memory usage is higher than 31.5Gi or storage is greater than 90Gi.

 

 

 

Reference

1.https://kubernetes.io/docs/tasks/administer-cluster/reserve-compute-resources/

2.https://kubernetes.io/ko/docs/concepts/configuration/manage-resources-containers/

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

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함