Kubernetes

Kubernetes, Kubernetes Architecture, Object, Controller, Label, Selector, Annotation

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ๋ถ„์‚ฐํ™˜๊ฒฝ์—์„œ ์ปจํ…Œ์ด๋„ˆ ๋ผ์ดํ”„์‚ฌ์ดํด์„ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๋„๊ตฌ์ด๋‹ค.

๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ปจํ…Œ์ด๋„ˆ๋กœ ๋‚˜๋ˆ„์–ด์ ธ์„œ ๊ด€๋ฆฌ ํฌ์ธํŠธ๊ฐ€ ๋Š˜์–ด๋‚ฌ๊ณ  ์ด๋ฅผ ๊ด€๋ฆฌํ•ด ์ค„ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ์ฟ ๋ฒ„๋„คํ„ฐ์Šค๊ฐ€ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ๊ณณ์€ ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค, ML ์›Œํฌ๋กœ๋“œ ๋“ฑ์ด๋‹ค.

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์ฒ ํ•™

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ์‹œ์Šคํ…œ ๊ตฌ์ถ•์„ ์œ„ํ•œ ์ˆ˜์ž‘์—…์„ ์ตœ์†Œํ•˜๊ณ , ์‹œ์Šคํ…œ์„ ์…€ํ”„ ์„œ๋น„์Šค๋กœ ์šด์˜ํ•˜๋Š” ๋ชฉ์ ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

Master Node ๊ตฌ์กฐ

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” Master์™€ Note๋กœ ๊ตฌ์„ฑ๋œ๋‹ค. Master๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ ๊ด€๋ฆฌํ•˜๋Š” ์—ญํ• ์„ ํ•˜๊ณ  Node๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด ์›Œ์ปค๋กœ VM ํ˜น์€ ๋ฌผ๋ฆฌ๋จธ์‹ ์ด๋‹ค.

์˜ค๋ธŒ์ ํŠธ์™€ ์ปจํŠธ๋กค๋Ÿฌ

Object (์˜ค๋ธŒ์ ํŠธ)

Pod

ํŒŒ๋“œ๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์—์„œ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ€์žฅ ์ž‘์€ ๋‹จ์œ„๋กœ ์ปจํ…Œ์ด๋„ˆ ๊ทธ๋ฃน์˜ ์ปจํ…Œ์ด๋„ˆ ์‚ฌ์ด์— ์Šคํ† ๋ฆฌ์ง€, IP ๋“ฑ ์ž์›์„ ๊ณต์œ ํ•œ๋‹ค. ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„์œผ๋กœ ๋„์ปค๋ฅผ ์ฃผ๋กœ ์‚ฌ์šฉํ•˜๋ฉฐ, ํŒŒ๋“œ ๋ผ์ดํ”Œ ์‚ฌ์ดํด์€ kubelet์ด ๊ด€๋ฆฌํ•œ๋‹ค.

Volume

ํŒŒ๋“œ๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ์Šคํ† ๋ฆฌ์ง€๋‹ค. ํŒŒ๋“œ๋Š” stateless ํ•˜๋ฏ€๋กœ ๋ฐ์ดํ„ฐ ๋ณด์กด์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋ณผ๋ฅจ์„ ๋งŒ๋“ค๊ณ  ํŒŒ๋“œ์— ๋ถ™์—ฌ์„œ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค. ๋ณผ๋ฅจ์„ PV (Persistent Volume)๋ผ๊ณ  ํ•˜๋ฉฐ, PV ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์—๋Š” ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด ๋†“๋Š” static ๋ฐฉ๋ฒ•๊ณผ ์š”์ฒญ์ด ์žˆ์„ ๋•Œ ๋งŒ๋“œ๋Š” dynamic ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. dynamic ๋ฐฉ๋ฒ•์€ PVC์— storageClassName ํ•ญ๋ชฉ์— StorageClass ๋ช…์„ ๋„ฃ์œผ๋ฉด StorageClass๋ฅผ ํ†ตํ•ด PV๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. PV๋Š” ์ง์ ‘ ์ปจํ…Œ์ด๋„ˆ์™€ ์—ฐ๊ฒฐ๋˜์ง€ ์•Š์œผ๋ฉฐ, PVC์— ์ •์˜ํ•œ ์กฐ๊ฑด์— ๋งž๋Š” PV๊ฐ€ ์žˆ์œผ๋ฉด ๋ฐ”์ธ๋”ฉํ•œ๋‹ค. ํŒŒ๋Š” PVC๋ฅผ ๋ณผ๋ฅจ์œผ๋กœ ์ธ์‹ํ•˜์—ฌ ์‚ฌ์šฉํ•œ๋‹ค.

Service

ํŒŒ๋“œ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๋„คํŠธ์›Œํฌ๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค. ํŒŒ๋“œ๊ฐ€ IP๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด๋„ ์„œ๋น„์Šค๊ฐ€ ์—†์œผ๋ฉด ํด๋Ÿฌ์Šคํ„ฐ ์™ธ๋ถ€๋กœ ๋…ธ์ถœํ•  ์ˆ˜ ์—†๋‹ค. ํ•˜์ง€๋งŒ SSL ์ธ์ฆ์„œ ์ฒ˜๋ฆฌ๋‚˜ URI ๊ธฐ๋ฐ˜ ๋ผ์šฐํŒ…์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.

Ingress

ํด๋Ÿฌ์Šคํ„ฐ ์™ธ๋ถ€์—์„œ ๋‚ด๋ถ€๋กœ ์ ‘๊ทผํ•˜๋Š” ์š”์ฒญ๋“ค์„ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ• ์ง€ ๊ทœ์น™์„ ์ •์˜ํ•˜๊ณ  ๊ทœ์น™์— ๋”ฐ๋ผ ํŠธ๋ž˜ํ”ฝ์„ ๊ด€๋ฆฌํ•œ๋‹ค. ์ธ๊ทธ๋ ˆ์Šค๋Š” L7 ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ ๊ธฐ๋Šฅ์œผ๋กœ URI ๊ธฐ๋ฐ˜ ๋ผ์šฐํŒ…์„ ์ œ๊ณตํ•œ๋‹ค.

Namespace

๋…ผ๋ฆฌ์ ์œผ๋กœ ๋ถ„๋ฆฌ๋œ ์ž‘์—…๊ทธ๋ฃน์œผ๋กœ Namespace๋ณ„๋กœ ๋ฆฌ์†Œ์Šค๋ฅผ ๊ฒฉ๋ฆฌ๋˜์–ด ์žˆ๋‹ค.

ConfigMap

ํ™˜๊ฒฝ์„ค์ •์„ ์ €์žฅํ•˜๋Š” ์˜ค๋ธŒ์ ํŠธ์ด๋‹ค.

Secret

์ปจํ”ผ๊ทธ๋งต์— ์ €์žฅํ•  ์ˆ˜ ์—†๋Š” ๋ฏผ๊ฐ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” ์˜ค๋ธŒ์ ํŠธ์ด๋‹ค. base64 ๊ฐ’์œผ๋กœ ์ €์žฅํ•œ๋‹ค.

์˜ค๋ธŒ์ ํŠธ ํ…œํ”Œ๋ฆฟ

# ์—ฌ๋Ÿฌ ๊ฐœ ํŒŒ์ผ์„ ํฌํ•จํ•  ๋•Œ ๊ตฌ๋ถ„์ž
# comment apiVersion: # ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์˜ API ๋ฒ„์ „
kind: # ์˜ค๋ธŒ์ ํŠธ ์ข…๋ฅ˜ (Pod, Deployment, Service ๋“ฑ)
metadata: # ์˜ค๋ธŒ์ ํŠธ ๋ฉ”ํƒ€์ •๋ณด (์ด๋ฆ„, ๋ ˆ์ด๋ธ” ๋“ฑ)
spec: # ํŒŒ๋“œ ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ ์ •๋ณด

์ปจํŠธ๋กค๋Ÿฌ (Controller)

์ปจํŠธ๋กค๋Ÿฌ๋Š” ํŒŒ๋“œ ์ƒํƒœ ๊ด€๋ฆฌ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋ ˆํ”Œ๋ฆฌ์นด์…‹, ๋””ํ”Œ๋กœ์ด๋จผํŠธ, ๋ฐ๋ชฌ์…‹, ์Šคํ…Œ์ดํŠธํ’€ ์…‹, ์žก ๋“ฑ์ด ์žˆ๋‹ค.

ReplicaSet Controller

์ง€์ •ํ•œ ์‹คํ–‰ ํŒŒ๋“œ ์ˆ˜๋ฅผ ์œ ์ง€์‹œํ‚ค๋Š” ์—ญํ• ์„ ํ•˜๋Š” Controller์ด๋‹ค. ๋””ํ”Œ๋กœ์ด๋จผํŠธ๊ฐ€ ์ƒ์œ„ ๊ฐœ๋…์ด๋‹ค.

Deployment Controller

ํŒŒ๋“œ๋ฅผ ๋ฐฐํฌํ•˜๊ณ ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” Controller์ด๋‹ค. ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค deployment๋ฅผ ์„ค์ •ํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋‹ค. deployment๋ฅผ ์„ค์ •ํ•˜๋ฉด replica ๊ฐ’์— ๋”ฐ๋ผ ํŒŒ๋“œ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๊ด€๋ฆฌํ•  ReplicaSet๋„ ์ƒ์„ฑํ•œ๋‹ค.

DaemonSet Controller

๋กœ๊ทธ ์ˆ˜์ง‘๊ธฐ์™€ ๊ฐ™์ด ๋ชจ๋“  ๋…ธ๋“œ์— ํŒŒ๋“œ ํ•˜๋‚˜์”ฉ ๊ตฌ์ถ•ํ•  ๋•Œ ๊ฐ ํŒŒ๋“œ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” Controller์ด๋‹ค.

StatefulSet Controller

์Šคํ…Œ์ดํŠธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํŒŒ๋“œ๋“ค์„ ๊ด€๋ฆฌํ•˜๋Š” Controller์ด๋‹ค. ์ˆœ์„œ๋ฅผ ์ง€์ •ํ•˜์—ฌ ํŒŒ๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ๋ณผ๋ฅจ์„ ์ง€์ •ํ•˜์—ฌ ํŒŒ๋“œ๊ฐ€ ๋‚ด๋ ค๊ฐ€๋„ ๋ฐ์ดํ„ฐ๋ฅผ ์žƒ์ง€ ์•Š๋Š”๋‹ค. ํŒŒ๋“œ ์ด๋ฆ„ ๋’ค์— ์ˆœ์„œ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ˆซ์ž๊ฐ€ ๋ถ™๋Š”๋‹ค.(0 ~ n)

Job Controller

๋ฐฐ์น˜ ์ž‘์—… ๊ฐ™์ด ํ•œ๋ฒˆ ์‹คํ–‰๋˜๊ณ  ๋๋‚˜๋Š” ์ž‘์—…์šฉ ํŒŒ๋“œ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” Controller ์ด๋‹ค.

CronJob Controller

์ฃผ๊ธฐ์ ์œผ๋กœ ์‹คํ–‰ํ•˜๋Š” Job์„ Controller ํ•œ๋‹ค.

Label, Selector, Annotation

๋ ˆ์ด๋ธ”์€ ํŠน์ • ์˜ค๋ธŒ์ ํŠธ ์ธ์‹ํ‘œ์ด๊ณ , ์–ด๋…ธํ…Œ์ด์…˜์€ ์˜ค๋ธŒ์ ํŠธ ์ฃผ์„, ์…€๋ ‰ํ„ฐ๋Š” ํŠน์ • ๋ ˆ์ด๋ธ”์„ ์ฐพ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์•„ํ‚คํ…์ฒ˜

Kubernetes ๋™์ž‘์ ˆ์ฐจ

์‚ฌ์šฉ์ž๊ฐ€ API Server์— ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑํ•˜๋ผ๊ณ  ์ „๋‹ฌํ•˜๋ฉด Scheduler๊ฐ€ ์–ด๋Š ๋…ธ๋“œ์— ์ƒ์„ฑํ• ์ง€ ์Šค์ผ€์ค„๋งํ•˜๊ณ  ์ •๋ณด๋ฅผ etcd์— ์ €์žฅํ•˜๋ฉด kubelet์ด ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค ์•„ํ‚คํ…์ฒ˜๊ฐ€ ์–ด๋ ค์šด ์  ์ค‘์˜ ํ•˜๋‚˜๋Š” ์„œ๋น„์Šค๊ฐ€ ์ฆ๊ฐ€ํ•  ์ˆ˜๋ก, ์„œ๋น„์Šค๊ฐ„ ์—ฐ๊ณ„๊ฐ€ ๋ณต์žกํ•ด์ ธ์„œ ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ์–ด๋Š ์„œ๋น„์Šค์— ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š”์ง€ ์ฐพ๊ธฐ๊ฐ€ ์–ด๋ ต๋‹ค. ๊ทธ๋ž˜์„œ ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค์—์„œ๋Š” ์„œ๋น„์Šค๊ฐ„ ๋ชจ๋‹ˆํ„ฐ๋ง์ด ์ค‘์š”ํ•˜๋‹ค.

์ฐธ๊ณ ์ž๋ฃŒ

Kubernetes components, https://kubernetes.io/ko/docs/concepts/overview/components/ Kubernetes architecture, https://luludansmarue.github.io/kubernetes-docker-lab/k8s/architecture.html Kubernetes Concepts Condensed In A Diagram, http://www.mycloudreference.com/kubernetes-concepts-condensed-in-a-diagram/ Patterns for Composite Containers, https://kubernetes.io/blog/2015/06/the-distributed-system-toolkit-patterns/ Kubernetes NodePort vs LoadBalancer vs Ingress? When should I use what?, https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0 https://kubernetes.io/ko/docs/concepts/services-networking/service/#proxy-mode-userspace Kubernetes Ingress, Istio Gateway, https://binux.tistory.com/63?category=934681 https://medium.com/@zhaohuabing/which-one-is-the-right-choice-for-the-ingress-gateway-of-your-service-mesh-21a280d4a29c

Last updated