์ผ๋ฐ์ ์ผ๋ก ์ ํ๋ฆฌ์ผ์ด์ ์ ์ฌ๋ฐ๋ฅด๊ณ ์์ ์ ์ธ ์๋์ ์ํด์๋ ํญ์ ์ ์ฉ ๋ฆฌ์์ค ํ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ ๊ณตํด์ผ ํฉ๋๋ค. ํ์ง๋ง ์ฌ๋ฌ ์ ํ๋ฆฌ์ผ์ด์ ์ด ๋์ผํ ์ ์์ผ๋ก ์คํ๋๊ณ ์๋ค๋ฉด ์ด๋ป๊ฒ ๋ ๊น์? ๊ทธ๋ค ๊ฐ๊ฐ์๊ฒ ์ต์ํ์ ํ์ํ ์์์ ์ ๊ณตํ๋ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น? ์์ ์๋น๋ฅผ ์ด๋ป๊ฒ ์ ํํ ์ ์๋์? ๋ ธ๋ ๊ฐ์ ๋ก๋๋ฅผ ์ฌ๋ฐ๋ฅด๊ฒ ๋ถ๋ฐฐํ๋ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น? ์ ํ๋ฆฌ์ผ์ด์ ๋ก๋๊ฐ ์ฆ๊ฐํ๋ ๊ฒฝ์ฐ ์ํ ํ์ฅ ๋ฉ์ปค๋์ฆ์ด ์๋ํ๋๋ก ํ๋ ค๋ฉด ์ด๋ป๊ฒ ํด์ผ ํฉ๋๊น?
์์คํ ์ ์กด์ฌํ๋ ์ฃผ์ ๋ฆฌ์์ค ์ ํ๋ถํฐ ์์ํด์ผ ํฉ๋๋ค. ๋ฌผ๋ก ์ด๋ ํ๋ก์ธ์ ์๊ฐ๊ณผ RAM์ ๋๋ค. k8s ๋งค๋ํ์คํธ์์ ์ด๋ฌํ ๋ฆฌ์์ค ์ ํ์ ๋ค์ ๋จ์๋ก ์ธก์ ๋ฉ๋๋ค.
- CPU - ์ฝ์ด ๋ด
- RAM - ๋ฐ์ดํธ ๋จ์
๋ํ ๊ฐ ๋ฆฌ์์ค์ ๋ํด ๋ ๊ฐ์ง ์ ํ์ ์๊ตฌ ์ฌํญ์ ์ค์ ํ ์ ์์ต๋๋ค. ์์ฒญ ะธ ์ ํ. ์์ฒญ - ์ปจํ ์ด๋(๋ฐ ํฌ๋ ์ ์ฒด)๋ฅผ ์คํํ๊ธฐ ์ํ ๋ ธ๋์ ์ฌ์ ๋ฆฌ์์ค์ ๋ํ ์ต์ ์๊ตฌ ์ฌํญ์ ์ค๋ช ํ๋ ๋ฐ๋ฉด, ์ ํ์ ์ปจํ ์ด๋์ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ฆฌ์์ค์ ๋ํ ์๊ฒฉํ ์ ํ์ ์ค์ ํฉ๋๋ค.
๋งค๋ํ์คํธ๊ฐ ๋ ์ ํ์ ๋ชจ๋ ๋ช ์์ ์ผ๋ก ์ ์ํ ํ์๋ ์์ง๋ง ๋์์ ๋ค์๊ณผ ๊ฐ๋ค๋ ์ ์ ์ดํดํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค.
- ๋ฆฌ์์ค์ ์ ํ๋ง ๋ช ์์ ์ผ๋ก ์ง์ ๋ ๊ฒฝ์ฐ ์ด ๋ฆฌ์์ค์ ๋ํ ์์ฒญ์ ์๋์ผ๋ก ์ ํ๊ณผ ๋์ผํ ๊ฐ์ ์ฌ์ฉํฉ๋๋ค(์ค๋ช ์ํฐํฐ๋ฅผ ํธ์ถํ์ฌ ์ด๋ฅผ ํ์ธํ ์ ์์). ์ ๊ฒ๋ค. ์ค์ ๋ก ์ปจํ ์ด๋๋ ์คํํ๋ ๋ฐ ํ์ํ ๋ฆฌ์์ค ์๊ณผ ๋์ผํ ์์ผ๋ก ์ ํ๋ฉ๋๋ค.
- ๋ฆฌ์์ค์ ๋ํด ์์ฒญ๋ง ๋ช ์์ ์ผ๋ก ์ง์ ๋ ๊ฒฝ์ฐ ์ด ๋ฆฌ์์ค์๋ ๋ ๋์ ์ ํ์ด ์ค์ ๋์ง ์์ต๋๋ค. ์ปจํ ์ด๋๋ ๋ ธ๋ ์์ฒด์ ๋ฆฌ์์ค์ ์ํด์๋ง ์ ํ๋ฉ๋๋ค.
ํน์ ์ปจํ ์ด๋ ์์ค๋ฟ๋ง ์๋๋ผ ๋ค์ ์ํฐํฐ๋ฅผ ์ฌ์ฉํ์ฌ ๋ค์์คํ์ด์ค ์์ค์์๋ ๋ฆฌ์์ค ๊ด๋ฆฌ๋ฅผ ๊ตฌ์ฑํ ์๋ ์์ต๋๋ค.
- ์ ํ ๋ฒ์ โ ์ปจํ ์ด๋/ํฌ๋ ์์ค์ ์ ํ ์ ์ฑ ์ ns ๋จ์๋ก ์ค๋ช ํ๋ฉฐ ์ปจํ ์ด๋/ํฌ๋์ ๋ํ ๊ธฐ๋ณธ ์ ํ์ ์ค๋ช ํ๊ณ ๋ช ๋ฐฑํ ๋ฑ๋ฑํ ์ปจํ ์ด๋/ํฌ๋(๋๋ ๊ทธ ๋ฐ๋) ์์ฑ์ ๋ฐฉ์งํ๊ณ ๊ฐ์๋ฅผ ์ ํํ๋ ๋ฐ ํ์ํฉ๋๋ค. ํ๋ ๋ฐ ์์ฒญ ๊ฐ์ ๊ฐ๋ฅํ ์ฐจ์ด๋ฅผ ๊ฒฐ์ ํฉ๋๋ค.
- ๋ฆฌ์์คํ ๋น๋ โ ns์ ๋ชจ๋ ์ปจํ ์ด๋์ ๋ํ ์ผ๋ฐ์ ์ธ ์ ํ ์ ์ฑ ์ ์ค๋ช ํ๊ณ ์ผ๋ฐ์ ์ผ๋ก ํ๊ฒฝ ๊ฐ ๋ฆฌ์์ค๋ฅผ ๊ตฌ๋ถํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค(ํ๊ฒฝ์ด ๋ ธ๋ ์์ค์์ ์๊ฒฉํ๊ฒ ๊ตฌ๋ถ๋์ง ์์ ๊ฒฝ์ฐ ์ ์ฉํจ).
๋ค์์ ๋ฆฌ์์ค ์ ํ์ ์ค์ ํ๋ ๋งค๋ํ์คํธ์ ์์ ๋๋ค.
-
ํน์ ์ปจํ ์ด๋ ์์ค์์:
containers: - name: app-nginx image: nginx resources: requests: memory: 1Gi limits: cpu: 200m
์ ๊ฒ๋ค. ์ด ๊ฒฝ์ฐ nginx๋ก ์ปจํ ์ด๋๋ฅผ ์คํํ๋ ค๋ฉด ๋ ธ๋์ ์ต์ 1G์ ์ฌ์ RAM๊ณผ 0.2 CPU๊ฐ ํ์ํ๋ฉฐ, ์ปจํ ์ด๋๋ ์ต๋ 0.2 CPU์ ๋ ธ๋์์ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ชจ๋ RAM์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
-
์ ์ ์์ค ns์์:
apiVersion: v1 kind: ResourceQuota metadata: name: nxs-test spec: hard: requests.cpu: 300m requests.memory: 1Gi limits.cpu: 700m limits.memory: 2Gi
์ ๊ฒ๋ค. ๊ธฐ๋ณธ ns์ ๋ชจ๋ ์์ฒญ ์ปจํ ์ด๋ ํฉ๊ณ๋ CPU์ ๊ฒฝ์ฐ 300m, OP์ ๊ฒฝ์ฐ 1G๋ฅผ ์ด๊ณผํ ์ ์์ผ๋ฉฐ ๋ชจ๋ ์ ํ์ ํฉ๊ณ๋ CPU์ ๊ฒฝ์ฐ 700m, OP์ ๊ฒฝ์ฐ 2G์ ๋๋ค.
-
ns ๋จ์์ ์ปจํ ์ด๋์ ๋ํ ๊ธฐ๋ณธ ์ ํ:
apiVersion: v1 kind: LimitRange metadata: name: nxs-limit-per-container spec: limits: - type: Container defaultRequest: cpu: 100m memory: 1Gi default: cpu: 1 memory: 2Gi min: cpu: 50m memory: 500Mi max: cpu: 2 memory: 4Gi
์ ๊ฒ๋ค. ๋ชจ๋ ์ปจํ ์ด๋์ ๊ธฐ๋ณธ ๋ค์์คํ์ด์ค์์ ์์ฒญ์ CPU์ ๊ฒฝ์ฐ 100m, OP์ ๊ฒฝ์ฐ 1G๋ก ์ค์ ๋๊ณ ์ ํ์ CPU ๋ฐ 1G๋ก ์ค์ ๋ฉ๋๋ค. ๋์์ CPU(2m < x < 50) ๋ฐ RAM(2M < x < 500G)์ ๋ํ ์์ฒญ/์ ํ์์ ๊ฐ๋ฅํ ๊ฐ์๋ ์ ํ์ด ์ค์ ๋ฉ๋๋ค.
-
ํฌ๋ ์์ค ์ ํ์ฌํญ ns:
apiVersion: v1 kind: LimitRange metadata: name: nxs-limit-pod spec: limits: - type: Pod max: cpu: 4 memory: 1Gi
์ ๊ฒ๋ค. ๊ธฐ๋ณธ ns์ ๊ฐ ํฌ๋์๋ vCPU 4๊ฐ ๋ฐ 1G๋ก ์ ํ๋ฉ๋๋ค.
์ด์ ์ด๋ฌํ ์ ํ์ ์ค์ ํ๋ฉด ์ด๋ค ์ด์ ์ ์ป์ ์ ์๋์ง ๋ง์๋๋ฆฌ๊ณ ์ถ์ต๋๋ค.
๋ ธ๋ ๊ฐ ๋ก๋ ๋ฐธ๋ฐ์ฑ ๋ฉ์ปค๋์ฆ
์์๋ค์ํผ k8s ๊ตฌ์ฑ ์์๋ ๋ค์๊ณผ ๊ฐ์ ๋ ธ๋ ๊ฐ Pod ๋ฐฐํฌ๋ฅผ ๋ด๋นํฉ๋๋ค. ์ค์ผ์ค๋ฌ, ํน์ ์๊ณ ๋ฆฌ์ฆ์ ๋ฐ๋ผ ์๋ํฉ๋๋ค. ์ด ์๊ณ ๋ฆฌ์ฆ์ ์์ํ ์ต์ ์ ๋ ธ๋๋ฅผ ์ ํํ ๋ ๋ ๋จ๊ณ๋ฅผ ๊ฑฐ์นฉ๋๋ค.
- ํํฐ๋ง
- ๋ฒ์
์ ๊ฒ๋ค. ์ค๋ช ๋ ์ ์ฑ ์ ๋ฐ๋ผ ์ด๊ธฐ์ ๋ ธ๋๋ ์ธํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํฌ๋๋ฅผ ์์ํ ์ ์๋๋ก ์ ํ๋ฉ๋๋ค. ์ ์ด (๋ ธ๋์ ํฌ๋๋ฅผ ์คํํ๊ธฐ์ ์ถฉ๋ถํ ๋ฆฌ์์ค๊ฐ ์๋์ง ํ์ธํ๋ ๊ฒ - PodFitsResources ํฌํจ) ๊ทธ๋ฐ ๋ค์ ๊ฐ ๋ ธ๋์ ๋ํด ๋ค์์ ๋ฐ๋ฆ ๋๋ค. ์ฐ์ ์์ ํฌ์ธํธ๊ฐ ๋ถ์ฌ๋๊ณ (๋ ธ๋์ ๋ฌด๋ฃ ๋ฆฌ์์ค๊ฐ ๋ง์์๋ก ๋ ๋ง์ ํฌ์ธํธ๊ฐ ํ ๋น๋จ - LeastResourceAllocation/LeastRequestedPriority/BalancedResourceAllocation ํฌํจ) ๊ฐ์ฅ ๋ง์ ํฌ์ธํธ๊ฐ ์๋ ๋ ธ๋์์ ํฌ๋๊ฐ ์์๋ฉ๋๋ค(์ฌ๋ฌ ๋ ธ๋๊ฐ ๋์์ ์ด ์กฐ๊ฑด์ ์ถฉ์กฑํ๋ ๊ฒฝ์ฐ ๋ฌด์์๋ก ์ ํ๋ฉ๋๋ค).
๋์์, ๋
ธ๋์ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ฆฌ์์ค๋ฅผ ํ๊ฐํ ๋ ์ค์ผ์ค๋ฌ๊ฐ etcd์ ์ ์ฅ๋ ๋ฐ์ดํฐ์ ๋ฐ๋ผ ์๋ด๋๋ค๋ ์ ์ ์ดํดํด์ผ ํฉ๋๋ค. ์ด ๋
ธ๋์์ ์คํ๋๋ ๊ฐ Pod์ ์์ฒญ/์ ํ ๋ฆฌ์์ค ์์ ๋ํ ๊ฒ์ด์ง๋ง ์ค์ ๋ฆฌ์์ค ์๋น์๋ ํด๋น๋์ง ์์ต๋๋ค. ์ด ์ ๋ณด๋ ๋ช
๋ น ์ถ๋ ฅ์์ โโ์ป์ ์ ์์ต๋๋ค. kubectl describe node $NODE
์ :
# kubectl describe nodes nxs-k8s-s1
..
Non-terminated Pods: (9 in total)
Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits AGE
--------- ---- ------------ ---------- --------------- ------------- ---
ingress-nginx nginx-ingress-controller-754b85bf44-qkt2t 0 (0%) 0 (0%) 0 (0%) 0 (0%) 233d
kube-system kube-flannel-26bl4 150m (0%) 300m (1%) 64M (0%) 500M (1%) 233d
kube-system kube-proxy-exporter-cb629 0 (0%) 0 (0%) 0 (0%) 0 (0%) 233d
kube-system kube-proxy-x9fsc 0 (0%) 0 (0%) 0 (0%) 0 (0%) 233d
kube-system nginx-proxy-k8s-worker-s1 25m (0%) 300m (1%) 32M (0%) 512M (1%) 233d
nxs-monitoring alertmanager-main-1 100m (0%) 100m (0%) 425Mi (1%) 25Mi (0%) 233d
nxs-logging filebeat-lmsmp 100m (0%) 0 (0%) 100Mi (0%) 200Mi (0%) 233d
nxs-monitoring node-exporter-v4gdq 112m (0%) 122m (0%) 200Mi (0%) 220Mi (0%) 233d
Allocated resources:
(Total limits may be over 100 percent, i.e., overcommitted.)
Resource Requests Limits
-------- -------- ------
cpu 487m (3%) 822m (5%)
memory 15856217600 (2%) 749976320 (3%)
ephemeral-storage 0 (0%) 0 (0%)
์ฌ๊ธฐ์์๋ ํน์ ๋ ธ๋์์ ์คํ ์ค์ธ ๋ชจ๋ ํฌ๋์ ๊ฐ ํฌ๋๊ฐ ์์ฒญํ๋ ๋ฆฌ์์ค๋ฅผ ๋ณผ ์ ์์ต๋๋ค. ๋ค์์ cronjob-cron-events-1573793820-xt6q9 ํฌ๋๊ฐ ์์๋ ๋ ์ค์ผ์ค๋ฌ ๋ก๊ทธ์ ๋ชจ์ต์ ๋๋ค(์ด ์ ๋ณด๋ ์์ ๋ช ๋ น ์ธ์ -v=10์์ 10๋ฒ์งธ ๋ก๊น ์์ค์ ์ค์ ํ ๋ ์ค์ผ์ค๋ฌ ๋ก๊ทธ์ ๋ํ๋ฉ๋๋ค).
๋ก๊ทธ
I1115 07:57:21.637791 1 scheduling_queue.go:908] About to try and schedule pod nxs-stage/cronjob-cron-events-1573793820-xt6q9
I1115 07:57:21.637804 1 scheduler.go:453] Attempting to schedule pod: nxs-stage/cronjob-cron-events-1573793820-xt6q9
I1115 07:57:21.638285 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s5 is allowed, Node is running only 16 out of 110 Pods.
I1115 07:57:21.638300 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s6 is allowed, Node is running only 20 out of 110 Pods.
I1115 07:57:21.638322 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s3 is allowed, Node is running only 20 out of 110 Pods.
I1115 07:57:21.638322 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s4 is allowed, Node is running only 17 out of 110 Pods.
I1115 07:57:21.638334 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s10 is allowed, Node is running only 16 out of 110 Pods.
I1115 07:57:21.638365 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s12 is allowed, Node is running only 9 out of 110 Pods.
I1115 07:57:21.638334 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s11 is allowed, Node is running only 11 out of 110 Pods.
I1115 07:57:21.638385 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s1 is allowed, Node is running only 19 out of 110 Pods.
I1115 07:57:21.638402 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s2 is allowed, Node is running only 21 out of 110 Pods.
I1115 07:57:21.638383 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s9 is allowed, Node is running only 16 out of 110 Pods.
I1115 07:57:21.638335 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s8 is allowed, Node is running only 18 out of 110 Pods.
I1115 07:57:21.638408 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s13 is allowed, Node is running only 8 out of 110 Pods.
I1115 07:57:21.638478 1 predicates.go:1369] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s10 is allowed, existing pods anti-affinity terms satisfied.
I1115 07:57:21.638505 1 predicates.go:1369] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s8 is allowed, existing pods anti-affinity terms satisfied.
I1115 07:57:21.638577 1 predicates.go:1369] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s9 is allowed, existing pods anti-affinity terms satisfied.
I1115 07:57:21.638583 1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s7 is allowed, Node is running only 25 out of 110 Pods.
I1115 07:57:21.638932 1 resource_allocation.go:78] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s10: BalancedResourceAllocation, capacity 39900 millicores 66620178432 memory bytes, total request 2343 millicores 9640186880 memory bytes, score 9
I1115 07:57:21.638946 1 resource_allocation.go:78] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s10: LeastResourceAllocation, capacity 39900 millicores 66620178432 memory bytes, total request 2343 millicores 9640186880 memory bytes, score 8
I1115 07:57:21.638961 1 resource_allocation.go:78] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s9: BalancedResourceAllocation, capacity 39900 millicores 66620170240 memory bytes, total request 4107 millicores 11307422720 memory bytes, score 9
I1115 07:57:21.638971 1 resource_allocation.go:78] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s8: BalancedResourceAllocation, capacity 39900 millicores 66620178432 memory bytes, total request 5847 millicores 24333637120 memory bytes, score 7
I1115 07:57:21.638975 1 resource_allocation.go:78] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s9: LeastResourceAllocation, capacity 39900 millicores 66620170240 memory bytes, total request 4107 millicores 11307422720 memory bytes, score 8
I1115 07:57:21.638990 1 resource_allocation.go:78] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s8: LeastResourceAllocation, capacity 39900 millicores 66620178432 memory bytes, total request 5847 millicores 24333637120 memory bytes, score 7
I1115 07:57:21.639022 1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s10: TaintTolerationPriority, Score: (10)
I1115 07:57:21.639030 1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s8: TaintTolerationPriority, Score: (10)
I1115 07:57:21.639034 1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s9: TaintTolerationPriority, Score: (10)
I1115 07:57:21.639041 1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s10: NodeAffinityPriority, Score: (0)
I1115 07:57:21.639053 1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s8: NodeAffinityPriority, Score: (0)
I1115 07:57:21.639059 1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s9: NodeAffinityPriority, Score: (0)
I1115 07:57:21.639061 1 interpod_affinity.go:237] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s10: InterPodAffinityPriority, Score: (0)
I1115 07:57:21.639063 1 selector_spreading.go:146] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s10: SelectorSpreadPriority, Score: (10)
I1115 07:57:21.639073 1 interpod_affinity.go:237] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s8: InterPodAffinityPriority, Score: (0)
I1115 07:57:21.639077 1 selector_spreading.go:146] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s8: SelectorSpreadPriority, Score: (10)
I1115 07:57:21.639085 1 interpod_affinity.go:237] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s9: InterPodAffinityPriority, Score: (0)
I1115 07:57:21.639088 1 selector_spreading.go:146] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s9: SelectorSpreadPriority, Score: (10)
I1115 07:57:21.639103 1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s10: SelectorSpreadPriority, Score: (10)
I1115 07:57:21.639109 1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s8: SelectorSpreadPriority, Score: (10)
I1115 07:57:21.639114 1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s9: SelectorSpreadPriority, Score: (10)
I1115 07:57:21.639127 1 generic_scheduler.go:781] Host nxs-k8s-s10 => Score 100037
I1115 07:57:21.639150 1 generic_scheduler.go:781] Host nxs-k8s-s8 => Score 100034
I1115 07:57:21.639154 1 generic_scheduler.go:781] Host nxs-k8s-s9 => Score 100037
I1115 07:57:21.639267 1 scheduler_binder.go:269] AssumePodVolumes for pod "nxs-stage/cronjob-cron-events-1573793820-xt6q9", node "nxs-k8s-s10"
I1115 07:57:21.639286 1 scheduler_binder.go:279] AssumePodVolumes for pod "nxs-stage/cronjob-cron-events-1573793820-xt6q9", node "nxs-k8s-s10": all PVCs bound and nothing to do
I1115 07:57:21.639333 1 factory.go:733] Attempting to bind cronjob-cron-events-1573793820-xt6q9 to nxs-k8s-s10
์ฌ๊ธฐ์๋ ์ฒ์์ ์ค์ผ์ค๋ฌ๊ฐ ์์ํ ์ ์๋ 3๊ฐ์ ๋ ธ๋ ๋ชฉ๋ก์ ํํฐ๋งํ๊ณ ์์ฑํ๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค(nxs-k8s-s8, nxs-k8s-s9, nxs-k8s-s10). ๊ทธ๋ฐ ๋ค์ ๊ฐ์ฅ ์ ํฉํ ๋ ธ๋๋ฅผ ๊ฒฐ์ ํ๊ธฐ ์ํด ์ด๋ฌํ ๊ฐ ๋ ธ๋์ ๋ํ ์ฌ๋ฌ ๋งค๊ฐ๋ณ์(BalancedResourceAllocation, LeastResourceAllocation ํฌํจ)๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ ์๋ฅผ ๊ณ์ฐํฉ๋๋ค. ๊ถ๊ทน์ ์ผ๋ก ํฌ๋๋ ํฌ์ธํธ ์๊ฐ ๊ฐ์ฅ ๋ง์ ๋ ธ๋์ ์์ฝ๋ฉ๋๋ค(์ฌ๊ธฐ์ ๋์์ ๋ ๊ฐ์ ๋ ธ๋๋ ๋์ผํ ํฌ์ธํธ ์ 100037์ ๊ฐ์ง๋ฏ๋ก nxs-k8s-s10์ด๋ผ๋ ์์์ ๋ ธ๋๊ฐ ์ ํ๋ฉ๋๋ค).
์ถ๋ ฅ: ๋ ธ๋๊ฐ ์ ํ์ด ์ค์ ๋์ง ์์ ํฌ๋๋ฅผ ์คํํ๋ ๊ฒฝ์ฐ k8s์ ๊ฒฝ์ฐ(๋ฆฌ์์ค ์๋น ๊ด์ ์์) ์ด๋ ์ด ๋ ธ๋์ ๊ทธ๋ฌํ ํฌ๋๊ฐ ์ ํ ์๋ ๊ฒ๊ณผ ๋์ผํฉ๋๋ค. ๋ฐ๋ผ์ ์กฐ๊ฑด๋ถ๋ก ๊ณผ๋ํ ํ๋ก์ธ์ค(์: wowza)๊ฐ ์๋ ํฌ๋๊ฐ ์๊ณ ์ ํ์ด ์ค์ ๋์ง ์์ ๊ฒฝ์ฐ ์ด ํฌ๋๊ฐ ์ค์ ๋ก ๋ ธ๋์ ๋ชจ๋ ๋ฆฌ์์ค๋ฅผ ์๋นํ๋ ์ํฉ์ด ๋ฐ์ํ ์ ์์ง๋ง k8s์ ๊ฒฝ์ฐ ์ด ๋ ธ๋ ์ธ๋ก๋๋ ๊ฒ์ผ๋ก ๊ฐ์ฃผ๋๋ฉฐ ์์๋ฅผ ๋งค๊ธธ ๋(์ ํํ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ฆฌ์์ค๋ฅผ ํ๊ฐํ๋ ํฌ์ธํธ์์) ์์ ํฌ๋๊ฐ ์๋ ๋ ธ๋์ ๋์ผํ ์์ ํฌ์ธํธ๊ฐ ๋ถ์ฌ๋ฉ๋๋ค. ์ด๋ก ์ธํด ๊ถ๊ทน์ ์ผ๋ก ๋ ธ๋ ๊ฐ ๋ก๋๊ฐ ๊ณ ๋ฅด์ง ์๊ฒ ๋ถ์ฐ๋ ์ ์์ต๋๋ค.
ํฌ๋์ ํด๊ฑฐ
์์๋ค์ํผ ๊ฐ ํฌ๋์๋ 3๊ฐ์ง QoS ํด๋์ค ์ค ํ๋๊ฐ ํ ๋น๋ฉ๋๋ค.
- ๋ณด์ฅ โ ํฌ๋์ ๊ฐ ์ปจํ ์ด๋์ ๋ํด ๋ฉ๋ชจ๋ฆฌ ๋ฐ CPU์ ๋ํ ์์ฒญ ๋ฐ ์ ํ์ด ์ง์ ๋๊ณ ์ด ๊ฐ์ด ์ผ์นํด์ผ ํ ๋ ํ ๋น๋ฉ๋๋ค.
- ํ์ด ๊ฐ๋ฅ โ ํฌ๋์ ์๋ ํ๋ ์ด์์ ์ปจํ ์ด๋์ ์์ฒญ๊ณผ ์ ํ์ด ์๊ณ ์์ฒญ < ์ ํ์ด ์์ต๋๋ค.
- ์ต์ ์ ๋ ธ๋ ฅ โ ํฌ๋์ ๋จ์ผ ์ปจํ ์ด๋๊ฐ ๋ฆฌ์์ค ์ ํ์ด ์๋ ๊ฒฝ์ฐ
๋์์ ๋ ธ๋์ ๋ฆฌ์์ค(๋์คํฌ, ๋ฉ๋ชจ๋ฆฌ)๊ฐ ๋ถ์กฑํ๋ฉด kubelet์ ํฌ๋์ ์ฐ์ ์์์ QoS ํด๋์ค๋ฅผ ๊ณ ๋ คํ๋ ํน์ ์๊ณ ๋ฆฌ์ฆ์ ๋ฐ๋ผ ํฌ๋์ ์์๋ฅผ ๋งค๊ธฐ๊ณ ์ ๊ฑฐํ๊ธฐ ์์ํฉ๋๋ค. ์๋ฅผ ๋ค์ด RAM์ ๋ํด ์ด์ผ๊ธฐํ๋ ๊ฒฝ์ฐ QoS ํด๋์ค๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋ค์ ์์น์ ๋ฐ๋ผ ํฌ์ธํธ๊ฐ ๋ถ์ฌ๋ฉ๋๋ค.
- ๋ณด์ฅ: -์ผ
- ์ต๊ณ ์ ๋ ธ๋ ฅ: 1000
- ๋ฒ์คํธ ๊ฐ๋ฅ: min(max(2, 1000 - (1000 * memoryRequestBytes) / machineMemoryCapacityBytes), 999)
์ ๊ฒ๋ค. ๋์ผํ ์ฐ์ ์์๋ก kubelet์ ๋จผ์ ๋ ธ๋์์ ์ต์ ์ QoS ํด๋์ค๋ฅผ ๊ฐ์ถ ํฌ๋๋ฅผ ์ ๊ฑฐํฉ๋๋ค.
์ถ๋ ฅ: ๋ฆฌ์์ค๊ฐ ๋ถ์กฑํ ๊ฒฝ์ฐ ์ํ๋ ํฌ๋๊ฐ ๋ ธ๋์์ ์ ๊ฑฐ๋ ๊ฐ๋ฅ์ฑ์ ์ค์ด๋ ค๋ฉด ์ฐ์ ์์์ ํจ๊ป ์์ฒญ/ํ๋ ์ค์ ๋ ์ฒ๋ฆฌํด์ผ ํฉ๋๋ค.
์ ํ๋ฆฌ์ผ์ด์ ํฌ๋(HPA)์ ์ํ ์๋ ํ์ฅ์ ์ํ ๋ฉ์ปค๋์ฆ
k8s ์ํฐํฐ์ ๊ฐ์ด ๋ฆฌ์์ค(์์คํ - CPU/RAM ๋๋ ์ฌ์ฉ์ - rps) ์ฌ์ฉ์ ๋ฐ๋ผ Pod ์๋ฅผ ์๋์ผ๋ก ๋๋ฆฌ๊ฑฐ๋ ์ค์ด๋ ์์ ์ธ ๊ฒฝ์ฐ ๊ณ ์ ๋ ฅ ์ฆํญ๊ธฐ (์ํํ ํฌ๋ ์๋ ํฌ๊ธฐ ์กฐ์ ๊ธฐ). ๊ทธ ์๊ณ ๋ฆฌ์ฆ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- ๊ด์ฐฐ๋ ๋ฆฌ์์ค์ ํ์ฌ ํ๋ ๊ฐ์ด ๊ฒฐ์ ๋ฉ๋๋ค(currentMetricValue).
- ๋ฆฌ์์ค์ ๋ํด ์ํ๋ ๊ฐ์ด ๊ฒฐ์ ๋๋ฉฐ(desiredMetricValue), ์์คํ ๋ฆฌ์์ค์ ๋ํด ์์ฒญ์ ์ฌ์ฉํ์ฌ ์ค์ ๋ฉ๋๋ค.
- ํ์ฌ ๋ณต์ ๋ณธ ์๊ฐ ๊ฒฐ์ ๋ฉ๋๋ค(currentReplicas).
- ๋ค์ ๊ณต์์ ์ํ๋ ๋ณต์ ๋ณธ ์(desiredReplicas)๋ฅผ ๊ณ์ฐํฉ๋๋ค.
DesiredReplicas = [ currentReplicas * ( currentMetricValue / DesiredMetricValue )]
์ด ๊ฒฝ์ฐ ๊ณ์(currentMetricValue/desiredMetricValue)๊ฐ 1์ ๊ฐ๊น์ฐ๋ฉด ์ค์ผ์ผ๋ง์ด ๋ฐ์ํ์ง ์์ต๋๋ค(์ด ๊ฒฝ์ฐ ํ์ฉ๋๋ ์ค๋ฅ๋ ์ง์ ์ค์ ํ ์ ์์ผ๋ฉฐ ๊ธฐ๋ณธ์ ์ผ๋ก 0.1์ ๋๋ค).
CPU ์๋น์ ๋ฐ๋ผ ๋ณต์ ๋ณธ ์๋ฅผ ๋ณ๊ฒฝํด์ผ ํ๋ ์ฑ ํ ์คํธ ์ ํ๋ฆฌ์ผ์ด์ (๋ฐฐํฌ๋ผ๊ณ ์ค๋ช ๋จ)์ ์๋ฅผ ์ฌ์ฉํ์ฌ hpa๊ฐ ์๋ํ๋ ๋ฐฉ์์ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
-
์ ํ๋ฆฌ์ผ์ด์ ๋งค๋ํ์คํธ
kind: Deployment apiVersion: apps/v1beta2 metadata: name: app-test spec: selector: matchLabels: app: app-test replicas: 2 template: metadata: labels: app: app-test spec: containers: - name: nginx image: registry.nixys.ru/generic-images/nginx imagePullPolicy: Always resources: requests: cpu: 60m ports: - name: http containerPort: 80 - name: nginx-exporter image: nginx/nginx-prometheus-exporter resources: requests: cpu: 30m ports: - name: nginx-exporter containerPort: 9113 args: - -nginx.scrape-uri - http://127.0.0.1:80/nginx-status
์ ๊ฒ๋ค. ์ ํ๋ฆฌ์ผ์ด์ ํฌ๋๊ฐ ์ฒ์์ ๋ ๊ฐ์ ์ธ์คํด์ค์์ ์์๋๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. ๊ฐ ์ธ์คํด์ค์๋ ๋ ๊ฐ์ nginx ๋ฐ nginx-exporter ์ปจํ ์ด๋๊ฐ ํฌํจ๋์ด ์์ต๋๋ค. ์์ฒญ CPU์ฉ.
-
HPA ์ ์ธ๋ฌธ
apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: app-test-hpa spec: maxReplicas: 10 minReplicas: 2 scaleTargetRef: apiVersion: extensions/v1beta1 kind: Deployment name: app-test metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 30
์ ๊ฒ๋ค. ๋ฐฐํฌ ์ฑ ํ ์คํธ๋ฅผ ๋ชจ๋ํฐ๋งํ๊ณ CPU ํ์๊ธฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ ํ๋ฆฌ์ผ์ด์ ์ผ๋ก Pod ์๋ฅผ ์กฐ์ ํ๋ hpa๋ฅผ ๋ง๋ค์์ต๋๋ค(Pod๋ ์์ฒญํ CPU์ 30%๋ฅผ ์๋นํด์ผ ํจ). 2~10์ ๋ฒ์.
์ด์ ๋๋ก ์ค ํ๋์ ๋ถํ๋ฅผ ๊ฐํ ๊ฒฝ์ฐ hpa ์๋ ๋ฉ์ปค๋์ฆ์ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
# kubectl top pod NAME CPU(cores) MEMORY(bytes) app-test-78559f8f44-pgs58 101m 243Mi app-test-78559f8f44-cj4jz 4m 240Mi
์ ์ฒด์ ์ผ๋ก ์ฐ๋ฆฌ๋ ๋ค์์ ๊ฐ์ง๊ณ ์์ต๋๋ค:
- ์ํ๋ ๊ฐ(desiredMetricValue) - hpa ์ค์ ์ ๋ฐ๋ฅด๋ฉด 30%์ ๋๋ค.
- ํ์ฌ ๊ฐ(currentMetricValue) - ๊ณ์ฐ์ ์ํด ์ปจํธ๋กค๋ฌ ๊ด๋ฆฌ์๋ ๋ฆฌ์์ค ์๋น์ ํ๊ท ๊ฐ์ % ๋จ์๋ก ๊ณ์ฐํฉ๋๋ค. ์กฐ๊ฑด๋ถ๋ก ๋ค์์ ์ํํฉ๋๋ค.
- ๋ฉํธ๋ฆญ ์๋ฒ๋ก๋ถํฐ Pod ๋ฉํธ๋ฆญ์ ์ ๋๊ฐ์ ์์ ํฉ๋๋ค. 101m์ 4m
- ํ๊ท ์ ๋๊ฐ์ ๊ณ์ฐํฉ๋๋ค. ์ฆ, (101m + 4m) / 2 = 53m
- ์ํ๋ ๋ฆฌ์์ค ์๋น์ ๋ํ ์ ๋๊ฐ์ ๊ฐ์ ธ์ต๋๋ค. (์ด๋ฅผ ์ํด ๋ชจ๋ ์ปจํ ์ด๋์ ์์ฒญ์ด ํฉ์ฐ๋ฉ๋๋ค.) 60m + 30m = 90m
- ์์ฒญ Pod๋ฅผ ๊ธฐ์ค์ผ๋ก CPU ์๋น์ ํ๊ท ๋น์จ์ ๊ณ์ฐํฉ๋๋ค. 53m / 90m * 100% = 59%
์ด์ ๋ณต์ ๋ณธ ์๋ฅผ ๋ณ๊ฒฝํด์ผ ํ๋์ง ๊ฒฐ์ ํ๋ ๋ฐ ํ์ํ ๋ชจ๋ ๊ฒ์ด ์ค๋น๋์์ต๋๋ค. ์ด๋ฅผ ์ํด ๊ณ์๋ฅผ ๊ณ์ฐํฉ๋๋ค.
ratio = 59% / 30% = 1.96
์ ๊ฒ๋ค. ๋ณต์ ๋ณธ ์๋ ~2๋ฐฐ๋ก ์ฆ๊ฐํ์ฌ [2 * 1.96] = 4๊ฐ ๋์ด์ผ ํฉ๋๋ค.
๊ฒฐ๋ก : ๋ณด์๋ค์ํผ, ์ด ๋ฉ์ปค๋์ฆ์ด ์๋ํ๋ ค๋ฉด ๊ด์ฐฐ๋ ํฌ๋์ ๋ชจ๋ ์ปจํ ์ด๋์ ๋ํ ์์ฒญ์ด ์์ด์ผ ํ๋ค๋ ํ์ ์กฐ๊ฑด์ด ์์ต๋๋ค.
๋ ธ๋์ ์ํ ์๋ ํ์ฅ์ ์ํ ๋ฉ์ปค๋์ฆ(Cluster Autoscaler)
๋ถํ ์์ง๊ฐ ๋ฐ์ํ๋ ๋์ ์์คํ ์ ๋ฏธ์น๋ ๋ถ์ ์ ์ธ ์ํฅ์ ์คํํ๋ ค๋ฉด hpa๋ฅผ ๊ตฌ์ฑํ๋ ๊ฒ๋ง์ผ๋ก๋ ์ถฉ๋ถํ์ง ์์ต๋๋ค. ์๋ฅผ ๋ค์ด, hpa ์ปจํธ๋กค๋ฌ ๊ด๋ฆฌ์์ ์ค์ ์ ๋ฐ๋ผ ๋ณต์ ๋ณธ ์๋ฅผ 2๋ฐฐ๋ก ๋๋ ค์ผ ํ๋ค๊ณ ๊ฒฐ์ ํ์ง๋ง ๋ ธ๋์๋ ์ด๋ฌํ ์์ Pod๋ฅผ ์คํํ ์ ์๋ ์ฌ์ ๋ฆฌ์์ค๊ฐ ์์ต๋๋ค(์ฆ, ๋ ธ๋๋ ๋ฆฌ์์ค๋ฅผ ์์ฒญ ํฌ๋์ ์์ฒญํจ) ์ด๋ฌํ ํฌ๋๋ ๋ณด๋ฅ ์ค ์ํ๋ก ์ ํ๋ฉ๋๋ค.
์ด ๊ฒฝ์ฐ ์ ๊ณต์ ์ฒด์ ํด๋น IaaS/PaaS(์: GKE/GCE, AKS, EKS ๋ฑ)๊ฐ ์๋ ๊ฒฝ์ฐ ๋ค์๊ณผ ๊ฐ์ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ์ธ์. ๋ ธ๋ ์๋ ํฌ๊ธฐ ์กฐ์ ๊ธฐ. ํด๋ฌ์คํฐ ๋ฐ Pod์ ๋ฆฌ์์ค๊ฐ ๋ถ์กฑํ ๋ ํด๋ฌ์คํฐ์ ์ต๋ ๋ฐ ์ต์ ๋ ธ๋ ์๋ฅผ ์ค์ ํ๊ณ (ํด๋ผ์ฐ๋ ๊ณต๊ธ์ API๋ฅผ ํธ์ถํ์ฌ ๋ ธ๋๋ฅผ ์ฃผ๋ฌธ/์ ๊ฑฐํจ์ผ๋ก์จ) ํ์ฌ ๋ ธ๋ ์๋ฅผ ์๋์ผ๋ก ์กฐ์ ํ ์ ์์ต๋๋ค. ์์ฝํ ์ ์์ต๋๋ค(๋ณด๋ฅ ์ค ์ํ).
๊ฒฐ๋ก : ๋ ธ๋๋ฅผ ์๋ ํฌ๊ธฐ ์กฐ์ ํ๋ ค๋ฉด k8s๊ฐ ๋ ธ๋์ ๋ก๋๋ฅผ ์ฌ๋ฐ๋ฅด๊ฒ ํ๊ฐํ๊ณ ์ด์ ๋ฐ๋ผ ํด๋ฌ์คํฐ์ ๋ค์ ํฌ๋๋ฅผ ์์ํ ๋ฆฌ์์ค๊ฐ ์๋ค๊ณ ๋ณด๊ณ ํ ์ ์๋๋ก ํฌ๋ ์ปจํ ์ด๋์ ์์ฒญ์ ์ค์ ํด์ผ ํฉ๋๋ค.
๊ฒฐ๋ก
์ ํ๋ฆฌ์ผ์ด์ ์ด ์ฑ๊ณต์ ์ผ๋ก ์คํ๋๊ธฐ ์ํด ์ปจํ ์ด๋ ๋ฆฌ์์ค ์ ํ์ ์ค์ ํด์ผ ํ๋ ๊ฒ์ ์๋์ง๋ง ๋ค์๊ณผ ๊ฐ์ ์ด์ ๋ก ๊ทธ๋ ๊ฒ ํ๋ ๊ฒ์ด ๋ ์ข์ต๋๋ค.
- k8s ๋ ธ๋ ๊ฐ ๋ก๋ ๋ฐธ๋ฐ์ฑ ์ธก๋ฉด์์ ์ค์ผ์ค๋ฌ์ ๋ณด๋ค ์ ํํ ์๋์ ์ํด
- "ํฌ๋ ํด๊ฑฐ" ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ ๊ฐ๋ฅ์ฑ์ ์ค์ด๊ธฐ ์ํด
- HPA(์ ํ๋ฆฌ์ผ์ด์ ํฌ๋)์ ์ํ ์๋ ํ์ฅ์ด ์๋ํ๋ ค๋ฉด
- ํด๋ผ์ฐ๋ ๊ณต๊ธ์๋ฅผ ์ํ ๋ ธ๋์ ์ํ์ AutoScaling(Cluster AutoScaling)
๋ธ๋ก๊ทธ์์ ๋ค๋ฅธ ๊ธฐ์ฌ๋ ์ฝ์ด๋ณด์ธ์.
Tekton Pipeline - Kubernetes ๊ธฐ๋ฐ ํ์ดํ๋ผ์ธ Nginx์ฉ ๋์ ๋ชจ๋ ๋น๋ ์น์ธ์ด ์๋ ClickHouse์์ ์น์ธ์ด ์๋ ClickHouse๋ก ๋ง์ด๊ทธ๋ ์ด์ ํ ๊ฒฐ๊ณผ๋ ๋ฌด์์ ๋๊น? Golang์ ์ปจํ ์คํธ ํจํค์ง ์ดํด Docker ์ด๋ฏธ์ง๋ฅผ ์ถ์ํ๋ ์ธ ๊ฐ์ง ๊ฐ๋จํ ํธ๋ฆญ ๋ค์์ ์ด๊ธฐ์ข ์น ํ๋ก์ ํธ ๋ฐฑ์
์ถ์ฒ : habr.com