๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Infra/Kubernetes

[k8s] Kubernetes Scheduling

by The Future Engineer, Lucy 2024. 12. 4.
728x90
๋ฐ˜์‘ํ˜•

https://kubernetes.io/docs/concepts/scheduling-eviction/kube-scheduler/

 

Kubernetes Scheduler

In Kubernetes, scheduling refers to making sure that Pods are matched to Nodes so that Kubelet can run them. Scheduling overview A scheduler watches for newly created Pods that have no Node assigned. For every Pod that the scheduler discovers, the schedule

kubernetes.io


์Šค์ผ€์ค„๋ง์ด๋ž€?

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์—์„œ ์Šค์ผ€์ค„๋ง์ด๋ž€ kubelet์œผ๋กœ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ํฌ๋“œ๋ฅผ ๋…ธ๋“œ์— ํ• ๋‹นํ•˜๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค. ์Šค์ผ€์ค„๋Ÿฌ๋Š” ๋…ธ๋“œ์— ํ• ๋‹น๋˜์ง€ ์•Š์€ ์ƒˆ๋กœ ๋งŒ๋“ค์–ด์ง„ pod๋ฅผ ๊ฐ์‹œํ•œ๋‹ค. ๋ฐœ๊ฒฌํ•œ ๋ชจ๋“  ํฌ๋“œ์— ๋Œ€ํ•ด ์Šค์ผ€์ค„๋Ÿฌ๋Š” ํฌ๋“œ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ์ƒ์˜ ๋…ธ๋“œ๋ฅผ ์ฐพ๋Š”๋‹ค. ์Šค์ผ€์ค„๋Ÿฌ๋Š” ์Šค์ผ€์ค„๋ง ์›๋ฆฌ๋ฅผ ๊ณ ๋ คํ•˜์—ฌ ๋ฐฐ์น˜๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค.

Kube-scheduler

kube-scheduler๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์˜ ๊ธฐ๋ณธ ์Šค์ผ€์ค„๋Ÿฌ์ด๊ณ  ์ปจํŠธ๋กค ํ”Œ๋ ˆ์ธ์˜ ์ผ๋ถ€๋กœ ์‹คํ–‰๋œ๋‹ค kube-scheduler๋Š” ์›ํ•˜๊ฑฐ๋‚˜ ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ง์ ‘ ์Šค์ผ€์ค„๋ง ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ๋Œ€์‹  ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค๊ณ„๋˜์—ˆ๋‹ค.

kube-scheduler๋Š” ์ƒˆ๋กœ ์ƒ์„ฑ๋˜๊ฑฐ๋‚˜ ์•„์ง ์Šค์ผ€์ค„๋ง๋˜์ง€ ์•Š์€ ํฌ๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ์ตœ์ ์˜ ๋…ธ๋“œ๋ฅผ ์„ ํƒํ•œ๋‹ค. ํŒŒ๋“œ ์•ˆ ์ปจํ…Œ์ด๋„ˆ๋Š” ๋‹ค๋ฅธ ์š”๊ตฌ์‚ฌํ•ญ๋“ค์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์Šค์ผ€์ค„๋Ÿฌ๋Š” ํฌ๋“œ์˜ ๊ตฌ์ฒด์ ์ธ ์Šค์ผ€์ค„๋ง ์š”๊ตฌ์‚ฌํ•ญ์„ ๋งŒ์กฑํ•˜์ง€ ์•Š๋Š” ๋…ธ๋“œ๋ฅผ ๊ฑธ๋Ÿฌ๋‚ธ๋‹ค. ๋˜ํ•œ, API๋Š” ํŒŒ๋“œ๊ฐ€ ์ƒ์„ฑ๋  ๋•Œ ๊ทธ์— ๋Œ€ํ•œ ๋…ธ๋“œ๋ฅผ ๋ช…์‹œํ•˜๋„๋ก ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ๋Œ€๊ฒŒ๋Š” ํŠน์ดํ•œ ๊ฒฝ์šฐ์ด๋‹ค.

ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ํฌ๋“œ์— ๋Œ€ํ•œ ์Šค์ผ€์ค„๋ง ์š”๊ตฌ์‚ฌํ•ญ์„ ๋งŒ์กฑํ•˜๋Š” ๋…ธ๋“œ๋“ค์€ ์ด์šฉ๊ฐ€๋Šฅํ•œ ๋…ธ๋“œ๋ผ๊ณ  ํ•œ๋‹ค. ์ ํ•ฉํ•œ ๋…ธ๋“œ๊ฐ€ ์—†๋‹ค๋ฉด ํฌ๋“œ๋Š” ์Šค์ผ€์ค„๋Ÿฌ๊ฐ€ ๊ฐ€๋Šฅํ•œ ์œ„์น˜๋ฅผ ์ฐพ์„ ๋•Œ๊นŒ์ง€ ์Šค์ผ€์ค„๋งํ•˜์ง€ ์•Š๋Š”๋‹ค.

์Šค์ผ€์ค„๋ง ๊ฒฐ์ •์„ ์œ„ํ•ด ๊ณ ๋ คํ•ด์•ผ ํ•˜๋Š” ์š”์†Œ์—๋Š” ๊ฐœ๋ณ„ ๋ฐ ์ง‘๋‹จ ๋ฆฌ์†Œ์Šค ์š”๊ตฌ์‚ฌํ•ญ, ํ•˜๋“œ์›จ์–ด/์†Œํ”„ํŠธ์›จ์–ด/์ •์ฑ… ์ œ์•ฝ, affinity์™€ anit-affinity ์‚ฌ์–‘, ๋ฐ์ดํ„ฐ ์ง€์—ญ์„ฑ ๋“ฑ์ด ํฌํ•จ๋œ๋‹ค.

kube-scheduler๋Š” 2๋‹จ๊ณ„๋ฅผ ๊ฑธ์ณ ํฌ๋“œ์— ๋Œ€ํ•œ ๋…ธ๋“œ๋ฅผ ์„ ํƒํ•œ๋‹ค.

  1. Filtering
    filtering๋‹จ๊ณ„๋Š” ํฌ๋“œ๋ฅผ ์Šค์ผ€์ค„๋งํ•˜๊ธฐ ์œ„ํ•ด ์ด์šฉ ๊ฐ€๋Šฅํ•œ ๋…ธ๋“œ์˜ ์ง‘ํ•ฉ์€ ์ฐพ๋Š”๋‹ค. ์ด ๋‹จ๊ณ„ ์ดํ›„์— ๋…ธ๋“œ ๋ชฉ๋ก์— ์ ํ•ฉํ•œ ๋…ธ๋“œ๊ฐ€ ํฌํ•จ๋˜๋ฉฐ ๋‘ ๊ฐœ ์ด์ƒ์˜ ๋…ธ๋“œ๊ฐ€ ํฌํ•จ๋  ์ˆ˜๋„ ์žˆ๋‹ค. ๋ชฉ๋ก์ด ๋น„์–ด์žˆ์œผ๋ฉด ํ•ด๋‹น ํฌ๋“œ๋Š” ์•„์ง ์Šค์ผ€์ค„๋งํ•  ์ˆ˜ ์—†๋‹ค.
  2. Scoring
    scoring ๋‹จ๊ณ„์—์„œ ์Šค์ผ€์ค„๋Ÿฌ๋Š” ๊ฐ€์žฅ ์ ํ•ฉํ•œ ํŒŒ๋“œ ์œ„์น˜๋ฅผ ์„ ํƒํ•˜๊ธฐ ์œ„ํ•ด ๋‚˜๋จธ์ง€ ๋…ธ๋“œ๋“ค์— ์ˆœ์œ„๋ฅผ ๋งค๊ธด๋‹ค. ์Šค์ผ€์ค„๋Ÿฌ๋Š” scoring ๊ทœ์น™์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•„ํ„ฐ๋ง์—์„œ ์‚ด์•„๋‚จ์€ ๋…ธ๋“œ์— ์ ์ˆ˜๋ฅผ ํ• ๋‹นํ•œ๋‹ค.

Assigning Pods to Nodes

ํŠน์ • ๋…ธ๋“œ์—์„œ ์‹คํ–‰๋˜๋„๋ก ์ œํ•œํ•˜๊ฑฐ๋‚˜ ์„ ํ˜ธํ•˜๋„๋ก ํฌ๋“œ๋ฅผ ์ œํ•œํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ œ์•ฝ ์กฐ๊ฑด์„ ์„ค์ •ํ•  ํ•„์š”๊ฐ€ ์—†์œผ๋ฉฐ, ์Šค์ผ€์ค„๋Ÿฌ๋Š” ์ž๋™์ ์œผ๋กœ ํ•ฉ๋ฆฌ์ ์ธ ๋ฐฐ์น˜๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ํฌ๋“œ๊ฐ€ SSD๊ฐ€ ์—ฐ๊ฒฐ๋œ ๋…ธ๋“œ์— ๋ฐฐํฌ๋˜๋Š”์ง€ ํ™•์ธํ•˜๊ฑฐ๋‚˜ ๋งŽ์€ ํ†ต์‹ ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋‘ ๊ฐœ์˜ ์„œ๋กœ ๋‹ค๋ฅธ ์„œ๋น„์Šค์—์„œ ํฌ๋“œ๋ฅผ ๋™์ผํ•œ ๊ฐ€์šฉ์„ฑ ์˜์—ญ์œผ๋กœ ๊ณต๋™ ์œ„์น˜ ์ง€์ •ํ•˜๋Š” ๋“ฑ ๋ช‡ ๊ฐ€์ง€ ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค.

์•„๋ž˜ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜๋ฅผ ์‚ฌ์šฉํ•ด ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๊ฐ€ ํŠน์ • ํฌ๋“œ๋ฅผ ์Šค์ผ€์ค„๋งํ•  ์œ„์น˜๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋‹ค.

  • node label์— ๋Œ€ํ•œ nodeSelector ํ•„๋“œ
  • affinity์™€ anti-affinity
  • nodeName ํ•„๋“œ
  • Pod topology spread constraints

์ฒ˜์Œ์— ์ •๋ฆฌํ–ˆ๋˜ ๋‚ด์šฉ ์ž„์‹œ ์ €์žฅ ์•ˆ ๋ผ์„œ ๋‹ค ๋‚ ์•„๊ฐ€์„œ ์ •๋ฆฌ ์•ˆ ํ•˜๋ ค๋‹ค๊ฐ€ ๊ณต๋ถ€ํ•˜๋Š” ๊ฑฐ๋‹ˆ๊นŒ๋ผ๋Š” ๋งˆ์ธ๋“œ๋กœ ๋‹ค์‹œ ์—ด์‹ฌํžˆ ์ •๋ฆฌํ–ˆ๋‹ค.๐Ÿ˜‚
๋‹ค์Œ์—๋Š” ๋…ธ๋“œ ํ• ๋‹น ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ •๋ฆฌํ•˜๊ฒ ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•

'Infra > Kubernetes' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[k8s] Pod๋ž€?  (0) 2024.11.25
[k8s] Kubernetes ๊ตฌ์„ฑ ์š”์†Œ  (0) 2024.11.24
[k8s] Kubernetes๋ž€?  (1) 2024.11.16
[k8s] Kubernetes ๋กœ๊ทธ - PLG ๊ฐœ์š”  (0) 2024.11.04
[k8s] Kubernetes ๋กœ๊ทธ - PLG ๊ตฌ์ถ•  (0) 2024.11.04