๋ชฉ์ฐจ
ย Resource Requests
Pod๋ฅผ ์์ฑํ ๋ ํ์ CPU์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ง์ ํ ์ ์๋ค. ์ด๋ container์ ๋ํ resource request์ด๋ฉฐ, ์ปจํ
์ด๋์ ์ต์ CPU๋ ๋ฉ๋ชจ๋ฆฌ์ ๋ํ ์์ฒญ์ด๋ค.
Resource Request๋ฅผ ์ง์ ํ๋ฉด ์ค์ผ์ค๋ฌ๋ ๊ทธ ๊ฐ์ ๊ฐ์ง๊ณ Pod๋ฅผ Node์ ๋ฐฐ์น์ํฌ ๋ ๊ฐ์ฉํ ๋ฆฌ์์ค๋ฅผ ๊ฐ์ง node๋ฅผ ์๋ณํด ๋ฐฐ์นํ๋ค.
# pod-definition.yaml
apiVersion: v1
kind: Pod
metadata:
name: simple-webapp-color
labels:
name: simple-webapp-color
spec:
containers:
- name: simple-webapp-color
image: simple-webapp-color
ports:
- containerPort: 8080
resources:
requests:
memory: "4Gi"
cpu: 2
YAML
๋ณต์ฌ
ย CPU
Resource Request์์ Pod๊ฐ ์คํ๋๊ธฐ ์ํด ํ์ํ ์ต์ํ์ CPU ์์ ์ ์ํ๋ค.
CPU๋ vCPU(๊ฐ์ CPU)์ ๋์ผ์๋๋ค, CPU๋ 1m ์ด์์ ๊ฐ์ ๊ฐ์ ธ์ผ ํ๋ค.
1CPU๋ 1000m์ ํด๋นํ๋ฉฐ, โmโ์ mili๋ฅผ ์๋ฏธํ๋ค.
ย Memory
Resource Request์์ Pod๊ฐ ์คํ๋๊ธฐ ์ํด ํ์ํ ์ต์ํ์ Memory ์์ ์ ์ํ๋ค.
Mi, Gi ๊ฐ์ ์ ๋ฏธ์ฌ๋ฅผ ์ด์ฉํด ์ง์ ํ ์ ์์ผ๋ฉฐ ์ง์ ์ ์ผ๋ก ๋ฐ์ดํธ ๊ฐ์ ์ง์ ํ ์๋ ์๋ค.
1 G (Gigabyte) | 1,000,000,000 bytes |
1 M (Megabyte) | 1,000,000 bytes |
1 K (Kilobyte) | 1,000 bytes |
1 Gi (Gibibyte) | 1,073,741,824 bytes |
1 Mi (Mebibyte) | 1,048,576 bytes |
1 Ki (Kibibyte) | 1,024 bytes |
ย Resource Limits
๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ปจํ
์ด๋๋ Node์์ ์๋นํ ์ ์๋ ๋ฆฌ์์ค์ ๋ํ limit๊ฐ ์๋ค.
Pod์ ์ผ๋ถ ์ปจํ
์ด๋์ ์ฌ์ฉ CPU๋ Memory๊ฐ ๋ฌดํ์ ๋์ด๋๋ฉด Node๋ ๋ค๋ฅธ ๋ฆฌ์์ค ์ปจํ
์ด๋์ ํ๋ก์ธ์ค๋ฅผ ์ฃฝ์ผ ์ ์๋ค.
๋ฐ๋ผ์ Pod์ ๋ฆฌ์์ค ์ฌ์ฉ์ ๋ํ Limit์ ์ ํ ์ ์๋ค.
# pod-definition.yaml
apiVersion: v1
kind: Pod
metadata:
name: simple-webapp-color
labels:
name: simple-webapp-color
spec:
containers:
- name: simple-webapp-color
image: simple-webapp-color
ports:
- containerPort: 8080
resources:
requests:
memory: "1Gi"
cpu: 1
limits:
memory: "2Gi"
cpu: 2
YAML
๋ณต์ฌ
ย Exceed Limits
Exceeding CPU
โข
Pod๊ฐ CPU ํ๋๋ฅผ ์ด๊ณผํด ์์์ ์ฌ์ฉํ๋ ค๋ ๊ฒฝ์ฐ ์์คํ
์ด CPU๋ฅผ ์กฐ์ ํด ์ง์ ํ๋๋ฅผ ๋์ง ์๋๋ก ํ๋ค.
โข
๋ฐ๋ผ์ ์ปจํ
์ด๋๋ Limit ์ด์์ผ๋ก ๋ฆฌ์์ค๋ฅผ ์ฌ์ฉํ ์ ์๋ค
Exceeding Memory
โข
CPU์ ๋ฌ๋ฆฌ Memory๋ Limit์ ์ด๊ณผํ ๋ฉ๋ชจ๋ฆฌ ๋ฆฌ์์ค๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
โข
Pod๊ฐ ์ง์์ ์ผ๋ก ํ๋๋ฅผ ์ด๊ณผํ์ฌ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ๋ฉด Pod๋ ์ข
๋ฃ(terminated)๋๋ค.
โข
describe ๋ช
๋ น์ด๋ log๋ฅผ ํ์ธํ๋ฉด OOM(Out Of Memory) error๋ก ์ข
๋ฃ๋๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
ย Behavior
ย Default Behavior
โข
๊ธฐ๋ณธ์ ์ผ๋ก ์ฟ ๋ฒ๋คํฐ์ค๋ CPU, Memory์ ๋ํ Request, Limit๊ฐ ์๋ค
โ ์ด๋ค Pod๋ ์๋ฌด Node์์ ์ํ๋๋งํผ์ ๋ฆฌ์์ค๋ฅผ ์๋นํ๋ฉฐ, ์ด๋ ๋ค๋ฅธ Pod๋ฅผ ์ง์์ํค๋ ํ์์ ๋ถ๋ฌ ์ผ์ผํฌ ์ ์๋ค.
ย Behavior - CPU
ํด๋ฌ์คํฐ์์ CPU ๋ฆฌ์์ค๋ฅผ ๋๊ณ ๊ฒฝ์ํ๋ ๋ ๊ฐ์ Pod๊ฐ ์๋ค๊ณ ๊ฐ์ (์ค์ ๋ฆฌ์์ค๋ฅผ ์์ฒญํ๋ ๊ฒ์ ์ปจํ
์ด๋)
ย No Requests & No Limits
โข
Pod ํ๋๊ฐ ๋
ธ๋์ ๋ชจ๋ CPU ๋ฆฌ์์ค๋ฅผ ์๋นํ ์ ์์
โฆ
2๋ฒ Pod์ ๋ฆฌ์์ค ์์ฒญ์ ๋ง์
ย No Requests & Limits
โข
Pod๊ฐ ์๋์ผ๋ก Request๋ฅผ Limit๊ณผ ๋์ผํ๊ฒ ์ค์ ํจ
โข
Pod๋ง๋ค ์ ํด์ง Limit์ ๋ง๋ vCPU๊ฐ ๋ณด์ฅ๋จ
ย Requests & Limits
โข
๊ฐ Pod์๋ Request์ ๋ง๋ vCPU๊ฐ ๋ณด์ฅ๋จ
โข
๊ฐ Pod์ ์ต๋ ์ฌ์ฉ CPU๋ ์ ์๋ Limit๊น์ง๋ก ์ ํ๋จ
โข
์ด์์ ์ธ ์๋๋ฆฌ์ค๋ก ๋ณด์ด์ง๋ง Pod 1์ CPU ์ฌ์ดํด์ ๋ ์๋นํ๋ คํ๊ณ , Pod 2๋ CPU ์ฌ์ดํด์ ๊ทธ๋งํผ ์๋นํ๋ คํ์ง ์๋ ๊ฒฝ์ฐ๊ฐ ์์ ์ ์์
ย Requests & No Limits
โข
์์คํ
์ ์ถฉ๋ถํ CPU ์ฌ์ดํด์ด ์๋ค๋ฉด ๋ถํ์ํ๊ฒ Limit์ ์ค์ ํ ํ์๊ฐ ์์
โข
Request๊ฐ ์์ด ์ต์ vCPU๋ ๋ณด์ฅ๋ฐ์๊ณผ ๋์์ Limit์ด ์๊ธฐ ๋๋ฌธ์ Pod๋ง๋ค CPU ์ฌ์ดํด์ ์ต๋ํ ๋ง์ด ์ฌ์ฉํ ์ ์๋ค.
๋ชจ๋ Pod๋ Limit์ ๊ฐ์ง ํ์๋ ์์ง๋ง, Request๋ ์ ์๋์ด์ผ ์คํ์ ๋ณด์ฅ๋ฐ๋๋ค.
ย Behavior - Memory
ย No Requests & No Limits
โข
Pod ํ๋๊ฐ ๋
ธ๋์ ๋ชจ๋ Memory ๋ฆฌ์์ค๋ฅผ ์๋นํ ์ ์์
โฆ
2๋ฒ Pod์ ๋ฆฌ์์ค ์์ฒญ์ ๋ง์
ย No Requests & Limits
โข
Pod๊ฐ ์๋์ผ๋ก Request๋ฅผ Limit๊ณผ ๋์ผํ๊ฒ ์ค์ ํจ
โข
Pod๋ง๋ค ์ ํด์ง Limit์ ๋ง๋ Memory๊ฐ ๋ณด์ฅ๋จ
ย Requests & Limits
โข
๊ฐ Pod์๋ Request์ ๋ง๋ Memory๊ฐ ๋ณด์ฅ๋จ
โข
๊ฐ Pod์ ์ต๋ ์ฌ์ฉ Memory๋ ์ ์๋ Limit๊น์ง๋ก ์ ํ๋จ
ย Requests & No Limits
โข
๊ฐ Pod๋ ์ ์๋ Request์ ๋ฐ๋ฅธ Memory๊ฐ ๋ณด์ฅ๋จ
โข
์ด๋ค Pod๋ Node์ ๊ฐ์ฉํ Memory๋ฅผ ์๋ชจํ ์ ์์
โฆ
Pod 1์ด Pod 2๋ก๋ถํฐ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๋ ์์ฒญํ๋ฉด Pod 2๋ฅผ ์ฃฝ์ด๋ ์๋ฐ์ ์์
โฆ
Memory๋ CPU์ ๋ฌ๋ฆฌ ์กฐ์ ํ ์ ์๊ธฐ ๋๋ฌธ
ย LimitRange
โข
LimitRange๋ฅผ ์ ์ํ๋ฉด Request๋ Limit์ ์ค์ ํ์ง ์์ ์ปจํ
์ด๋์ ๊ธฐ๋ณธ๊ฐ์ ์ ์ํ ์ ์๋ค.
โข
Namespace ๋ ๋ฒจ์์๋ ์ ์ฉ์ด ๊ฐ๋ฅํ๋ฉฐ, ์ค๋ธ์ ํธ๋ก ์ทจ๊ธ๋๋ค.
โข
Pod๊ฐ ์์ฑ๋ ๋ LimitRange์ ๋ํ ์ํฅ์ ๋ฐ์ผ๋ฉฐ, ์ด๋ฏธ ๋ง๋ค์ด์ง Pod๋ ์ํฅ ๋ฐ์ง ์๋๋ค.
# limit-range-cpu.yaml
apiVersion: v1
kind: LimitRange
metadata:
name: cpu-resource-constraint
spec:
limits:
- default: # limit
cpu: 500m
defaultRequest: # request
cpu: 500m
max: # limit
cpu: "1"
min: # request
cpu: 100m
type: Container
YAML
๋ณต์ฌ
# limit-range-memory.yaml
apiVersion: v1
kind: LimitRange
metadata:
name: memory-resource-constraint
spec:
limits:
- default: # limit
memory: 1Gi
defaultRequest: # request
memory: 1Gi
max: # limit
memory: 1Gi
min: # request
memory: 500Mi
type: Container
YAML
๋ณต์ฌ
ย Resource Quotas
โข
๋ชจ๋ Pod๊ฐ ํน์ ์์ CPU๋ Memory๋ฅผ ์๋นํด์ ์๋๋ค๊ณ ํ๋ค๋ฉด Namespace ๋ ๋ฒจ์์ Quotas๋ฅผ ์์ฑํ ์ ์๋ค
โข
Resource Quota๋ ๋ค์์คํ์ด์ค ๋ ๋ฒจ ๊ฐ์ฒด๋ก, ์์ฒญ๊ณผ ํ๊ณ์ ๋ํ ์๊ฒฉํ ์ ํ์ ์ค์ ํ๊ธฐ ์ํด ์์ฑ๋ ์ ์๋ค.
# resource-quota.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
name: my-resource-quota
spec:
hard:
requests.cpu: 4
requests.memory: 4Gi
limits.cpu: 10
limits.memory: 10Gi
YAML
๋ณต์ฌ
ย ์ฐธ๊ณ
kube-scheduler๋ Pod์ ์๊ตฌ ๋ฆฌ์์ค์ Node์ ๊ฐ์ฉํ CPU์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํ์
ํ์ฌ Pod๋ฅผ ๋ฐฐ์นํ๋ค. ๋ง์ฝ Node์ ๊ฐ์ฉํ ๋ฆฌ์์ค๊ฐ ์ถฉ๋ถํ์ง ์๋ค๋ฉด scheduler๋ Pod๋ฅผ ๋ฐฐ์นํ์ง ์๊ณ Pending ์ํ๋ฅผ ์ ์งํ๋ค. kubectl describe pod ๋ช
๋ น์ด๋ฅผ ํตํด ํ์ธํด๋ณด๋ฉด CPU ๋ถ์กฑ์ ๋ํ ์ด๋ฒคํธ๋ฅผ ํ์ธํ ์ ์๋ค.

