Docker Orchestration๊ณผ Kubernetes

linยท2022๋…„ 8์›” 5์ผ
0
post-thumbnail

๐Ÿ“’ Docker Orchestration

์ปจํ…Œ์ด๋„ˆ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜์€ ์ปจํ…Œ์ด๋„ˆ์˜ ๋ฐฐํฌ, ๊ด€๋ฆฌ, ํ™•์žฅ, ๋„คํŠธ์›Œํ‚น์„ ์ž๋™ํ™”ํ•œ๋‹ค.

์ข…๋ฅ˜ :: Swarm, Kubernetes, Apache Mesos

์ปจํ…Œ์ด๋„ˆ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜์€ ์–ด๋””์— ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋ฐฐ์น˜ํ•˜๋Š” ๊ฒŒ ๋‚˜์€์ง€ ๊ด€๋ฆฌ๋ฅผ ํ•ด์ค€๋‹ค.
ex) ์ด ์ด๋ฏธ์ง€๋Š” 7๋ฒˆ ์„œ๋ฒ„๊ฐ€ ๋น ๋ฅผ๊ฑฐ์‹œ๋‹ค ๋ผ๊ณ  ์ž์ฒด ํŒ๋‹จ ํ•ด์ฃผ๋Š” ๊ฒƒ์ž„
replicas -> mode๊ฐ€ replicated๋ผ๋ฉด ์‹คํ–‰ ํ•  ์ปจํ…Œ์ด๋„ˆ ์ˆ˜๋ฅผ ๋ช…์‹œํ•ฉ๋‹ˆ๋‹ค.


Docker ์šด์˜ ์ „๋žต

  • Stable Base Image ์‚ฌ์šฉํ•˜๊ธฐ
  • ๊ฐ€๋Šฅํ•œ ์ž‘์€ ์ด๋ฏธ์ง€๋กœ ์‹œ์ž‘ํ•˜๊ธฐ
  • tag๋ช… ์ง€์ •ํ•˜๋Š” ์Šต๊ด€ ๊ฐ€์ง€๊ธฐ
  • ์„œ๋ช…๋œ ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , App์€ root๋กœ ์‹คํ–‰X
  • ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์—์„œ SSH(Secure Shell) ์‹คํ–‰ X!! ์ด๋ฏธ ๋„์ปค๊ฐ€ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์—
  • ์ปจํ…Œ์ด๋„ˆ ํ•˜๋‚˜์—๋Š” app ํ•œ๊ฐœ๋งŒ ์‹คํ–‰
  • ๋ณด์กด ๋˜์–ด์•ผ ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋Š” ์ปจํ…Œ์ด๋„ˆ ์™ธ๋ถ€์— ์ €์žฅ

๐Ÿ“’ Kubernetes

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ๋งŽ์€ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ณ ,, ๋ฐฐํฌ, ๊ด€๋ฆฌ,ํ™•์žฅ, ๋„คํŠธ์›Œํ‚น์„ ์ž๋™ํ™”ํ•œ๋‹ค.
container life-cycle์„ ๊ด€๋ฆฌ ๋ฐ ์ž๋™ํ™”ํ•˜๊ณ  workload ๊ด€๋ฆฌ๋ฅผ ์ž๋™ํ™”ํ•œ๋‹ค.

๐ŸŸ  ๋ฌผ๋ฆฌ์  ๊ตฌ์กฐ

๊ธฐ๋ณธ์ ์œผ๋กœ Kubernetes ๋Š” MasterNode์™€ WorkerNode๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ฅผ ๋ฐฐํฌํ•˜๋ฉด ํด๋Ÿฌ์Šคํ„ฐ๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.

๐Ÿ”น Master Node

kube-apiserver
etcd
kube-scheduler
kube-controller-manager

๐Ÿ”น Worker node

Kubelet : ๊ฐ ๋…ธ๋“œ, ์ปจํ…Œ์ด๋„ˆ ๊ด€๋ฆฌ
kube-proxy : ๋…ธํŠธ์˜ ๋„คํŠธ์›Œํฌ ํ”„๋ก์‹œ, ์ปจํ…Œ์ด๋„ˆ ํ†ต์‹ ์„ ์ œ์–ด
container-runtime : ์ปจํ…Œ์ด๋„ˆ ์šด์˜ ํ™˜๊ฒฝ ์ œ์–ด

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ๋„์ปค์™€ ๋‹ค๋ฅด๊ฒŒ POD ๋‹จ์œ„๋กœ ๊ด€๋ฆฌํ•œ๋‹ค.
POD : kubernetes์˜ ๊ธฐ๋ณธ ์‹คํ–‰/๋ฐฐํฌ ๋‹จ์œ„๋กœ ํ•˜๋‚˜ ์ด์ƒ์˜ ์ปจํ…Œ์ด๋„ˆ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.

๐ŸŸ  Kubernetes Cluster ๋‚ด ๋…ผ๋ฆฌ์  ๊ตฌ์กฐ

๐ŸŸ  ๋ฆฌ์†Œ์Šค

๋ชจ๋“  ๋ฆฌ์†Œ์Šค(pod,service,deployment,loadbalancing)์„ YAML ํŒŒ์ผ๋กœ ์ •์˜ํ•œ๋‹ค.

๋ฌธ๋ฒ•
Scalars (String/number)
Sequences (arrays/lists)
Mappings (hashes, dictionaries)

basic Template
apiVersion
kind (๋ฆฌ์†Œ์Šค ์ข…๋ฅ˜๋ฅผ ์„ค์ •)
metadata
spec : ํŒŒ๋“œ์˜ ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ ์ •๋ณด

๐Ÿ”น Namepsaces

๋™์ผํ•œ ๋ฌผ๋ฆฌ ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด์—์„œ ๋…ผ๋ฆฌ์ ์ธ ๋ถ„๋ฆฌ ๋‹จ์œ„์ด๋ฉฐ, ๋ฆฌ์†Œ์Šค๋ฅผ ๊ตฌ๋ถ„ํ•˜๋Š” ์šฉ๋„

  • default
  • kube-system : ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์‹œ์Šคํ…œ์—์„œ ์ƒ์„ฑํ•œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์œ„ํ•œ ๋„ค์ž„์ŠคํŽ˜์ด์Šค
  • kube-public : ๋ชจ๋“  ์‚ฌ์šฉ์ž๊ฐ€ ์ฝ๊ธฐ ๊ถŒํ•œ์œผ๋กœ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ ๋„ค์ž„์ŠคํŽ˜์ด์Šค

๋„ค์ž„ ์ŠคํŽ˜์ด์Šค ์ƒ์„ฑ/์‚ญ์ œ
kubectl create namespace[or ns] [๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ช…]
kubectl delete namespace[or ns] [๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ช…]

๐Ÿ”น ReplicaSet

์ง€์ •๋œ ์ˆซ์ž๋งŒํผ์˜ Pod๊ฐ€ ํ•ญ์ƒ ์‹คํ–‰๋˜๋„๋ก ์ง€์ • (default : 1)
spec : replicas : 3

๐Ÿ”น Deployment

  • Pod์™€ ReplicaSet์— ๋Œ€ํ•œ ์„ ์–ธ์  ์—…๋ฐ์ดํŠธ(๋‚ด๊ฐ€ ์›ํ•˜๋Š” ๋ชจ์–‘์„ ์ •์˜ํ•˜๋ฉด ์ตœ๋Œ€ํ•œ ๋งŒ๋“ค์–ด์ค€๋‹ค..์•ˆ๋˜๋ฉด ๋…ธ๋ ฅํ•œ๋‹ค)๋ฅผ ์ œ๊ณต

ex) ReplicaSet์ด ์„ค์ •์ด ๋˜๋ฉด pod๋ฅผ ๊ฐ•์ œ ์ข…๋ฃŒ์‹œ์ผœ๋„ ๊ณ„์† pod๋ฅผ ๋‹ค์‹œ ์ƒ์„ฑํ•˜์—ฌ ์œ ์ง€์‹œ์ผœ์ค€๋‹ค.

๐Ÿ”น Service

์™ธ๋ถ€๋กœ ๋…ธ์ถœ๋  ์ปจํ…Œ์ด๋„ˆ์˜ ๋„คํŠธ์›Œํฌ ํฌํŠธ ๊ด€๋ฆฌ ์„œ๋น„์Šค
ClusterIP : ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด์—์„œ POD๋“ค์˜ ํด๋Ÿฌ์Šคํ„ฐ๋ง์šฉ IP
NodePort : ๋…ธ๋“œ ๋ฐ–์—์„œ ์ ‘๊ทผํ•  ๋•Œ ํ• ๋‹น๋˜๋Š”
Loadbalancer : ํด๋Ÿฌ์Šคํ„ฐ ์™ธ๋ถ€์—์„œ ์ ‘๊ทผํ•  ๋•Œ ์ œ๊ณต๋˜๋Š” IP

๐Ÿ“’ kubectl

kubernetes ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” cli tool

๐ŸŸ  ์‚ฌ์šฉ๋ฒ•

kubectl [command] [TYPE] [NAME] [flag]

Kubectl get pods # ํŒŒ๋“œ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ
Kubectl get services # ์„œ๋น„์Šค ๋ฆฌ์ŠคํŠธ ์กฐํšŒ
Kubectl apply โ€“f py-app1.yml # py-app1.yml์— ์ •์˜๋œ ๋‚ด์šฉ ์ ์šฉ
Kubectl delete โ€“f py-app1.yml # py-app1.yml์— ์ •์˜๋œ ๋‚ด์šฉ ์ œ๊ฑฐ
Kubectl describe nodes my-node # my-node์— ๋Œ€ํ•œ ์ƒ์„ธ ์ •๋ณด ์ถœ๋ ฅ
Kubectl delete pod zoo # zoo๋ผ๋Š” ํŒŒ๋“œ ์‚ญ์ œ

๐ŸŸ  ์‹ค์Šต

์‹คํ–‰์ค‘์ธ POD ํ™•์ธ
>kubectl get po -A

์ฐธ์กฐ :
https://docker.com
https://www.redhat.com/ko/topics/containers/what-is-container-orchestration

profile
BE

0๊ฐœ์˜ ๋Œ“๊ธ€