๐Ÿ’ป/MLOps

[k8s] `kubectl top`

ruhz 2024. 1. 2. 17:12

`kubectl top`

kubectl top pods -n spark
kubectl top nodes

์œ„ ๋ช…๋ น์–ด๋กœ ํ•œ ๋ˆˆ์— ํŒŒ๋“œ๋ณ„๋กœ cpu, mem์„ ์–ผ๋งˆ๋‚˜ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธ์ด ๊ฐ€๋Šฅํ•˜๋ฉฐ, ๋…ธ๋“œ๋ณ„๋กœ๋„ ์–ผ๋งˆ๋‚˜ ์ž์›์ด ์‚ฌ์šฉ์ค‘์ธ์ง€ ํ™•์ธ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ํด๋Ÿฌ์Šคํ„ฐ์— ๊ฒฝ๊ณ ๋‚˜ ์žฅ์• ๊ฐ€ ๋‚˜๋ฉด, Grafana์— ๋“ค์–ด๊ฐ€์ง€ ์•Š๊ณ  ํ˜ธ๋‹ค๋‹ฅ ํ„ฐ๋ฏธ๋„์„์ผœ '๋ˆ„๊ฐ€ spark์œผ๋กœ ์ž์›์„ ์–ผ๋งˆ๋‚˜ ํ• ๋‹นํ•ด ์“ฐ๊ณ  ์žˆ๋‚˜'ํ™•์ธํ•˜๋Š” ๋ฐ์— ์ž์ฃผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค.

 

Kubernetes Metrics API

 

Resource metrics pipeline

For Kubernetes, the Metrics API offers a basic set of metrics to support automatic scaling and similar use cases. This API makes information available about resource usage for node and pod, including metrics for CPU and memory. If you deploy the Metrics AP

kubernetes.io

๊ธฐ๋ณธ์ ์œผ๋กœ๋Š” Metrics API๊ฐ€ ๊น”๋ ค์žˆ๋‹ค๋ฉด, ์œ„ ์•„ํ‚คํ…์ณ๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์žˆ๋Š” ๊ฒƒ์ด๋‹ค. ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„์— ๋Œ€ํ•œ ์ •๋ณด๋Š” cAdvisor(google)๋ฅผ ํ†ตํ•ด ์ˆ˜์ง‘. cAdvisor์˜ metric๊ณผ pod์˜ ์ •๋ณด๋ฅผ kubelet์ด ์ทจํ•ฉํ•œ๋‹ค. metrics-server๋Š” ๊ฐ ๋…ธ๋“œ kubelet์˜ ํ•ด๋‹น ์ •๋ณด๋ฅผ fetchํ•˜๊ณ , API Server ๋ฅผ ํ†ตํ•ด kubectl top๊ณผ Pod AutoScaling์„ ์œ„ํ•œ ์ปดํฌ๋„ŒํŠธ์— ์ œ๊ณตํ•œ๋‹ค. 

 

GitHub - google/cadvisor: Analyzes resource usage and performance characteristics of running containers.

Analyzes resource usage and performance characteristics of running containers. - GitHub - google/cadvisor: Analyzes resource usage and performance characteristics of running containers.

github.com

 

Kubernetes ๋ฆฌ์†Œ์Šค ์ธก์ •

`kubectl top` ์ž…๋ ฅ ์‹œ ํ‘œํ˜„๋˜๋Š” cpu ์ปฌ๋Ÿผ์˜ ๊ฐ’์€ ์–ด๋–ป๊ฒŒ ์ธก์ •๋œ ๊ฒƒ์ด๋ฉฐ ์–ด๋–ป๊ฒŒ ์ œ์–ด๋˜๊ณ  ์žˆ๋Š” ๊ฑด์ง€๋„ ํ™•์ธํ•ด๋ณธ๋‹ค.
cpu.shares, cpu.cfs_quota ๋“ฑ์—์„œ ๊ธฐ์ค€์ด ๋˜๋Š” ๊ฐ’์„ ๊ณ ์ •ํ•˜์—ฌ ์ƒ๋Œ€์ ์œผ๋กœ ์ •์˜๋˜๋Š” ๊ฐ’๋“ค์„ ์‚ฌ์šฉ์ž๊ฐ€ ์ ˆ๋Œ€์ ์ธ ์–‘์œผ๋กœ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๊ณ  ์žˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์•„๋ž˜ ๊ธ€์„ ์ฐธ๊ณ ํ•œ๋‹ค.

 

Kubernetes์—์„œ์˜ cpu requests, cpu limits๋Š” ์–ด๋–ป๊ฒŒ ์ ์šฉ๋ ๊นŒ :: Ibiza

Kubernetes์—์„œ์˜ cpu requests, cpu limits๋Š” ์–ด๋–ป๊ฒŒ ์ ์šฉ๋ ๊นŒ Kubernetes ์—์„œ๋Š” ์ปจํ…Œ์ด๋„ˆ ๋‹จ์œ„๋กœ resource๋ฅผ ํ• ๋‹นํ•  ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๊ธฐ์—๋Š” memory, cpu, ephemeral-storage, hugepages ๋“ฑ์ด ํฌํ•จ๋œ๋‹ค. ์ด ์ค‘์—์„œ cpu ์˜ requests,

kimmj.github.io

 

'Pod memory' vs 'Conatiner memory'

to be continue...