[Kubernetes] ๊ธฐ๋ง๊ณ ์‚ฌ ์ •๋ฆฌ 2

2024. 6. 25. 00:48ใ†ComputerScience/DockerKubernetes

 

 

 

 

 

Chap19. Controllers 
- 
์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ์—ฌ๋Ÿฌ SW๋“ค์˜ ์ง‘ํ•ฉ์ฒด 

* Controllers 

- take care of routine tasks to ensure the desired state (์–ŒํŒŒ์ผ) of the cluster matches the observed state (ํ˜„์ƒํƒœ)

- Each controller is responsible for a particular resource in the Kubernetes 
- 
์‚ฌ๋žŒ์ด ๊ฐœ์ž…ํ•˜๋Š” ์ผ์ด ์ค„์–ด๋“ฆ - ์ง์ ‘ ์†์œผ๋กœ ์ž…๋ ฅํ•˜์ง€ ์•Š์•„๋„, ์ˆ˜๋งŽ์€ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” SW๋“ค์ด ๊ฐœ๋ฐœ์ž๊ฐ€ ์š”๊ตฌํ•˜๋Š” ํ™˜๊ฒฝ(desired state)์„ observed state๋กœ ์ตœ๋Œ€ํ•œ ์ œ๊ณตํ•ด์•ผ ํ•จ / ๊ฐœ๋ฐœ์ž๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์—๊ฒŒ ๋ถ€ํƒํ•จ 

 

* Label – key-value pair – pod๊ณผ ๊ฐ™์€ objects์— attached 
- 
๋„์ปค์—์„œ๋Š” ๋‚ด ์ปดํ“จํ„ฐ๋ฅผ ๊ฐ€์ •ํ•จ, ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์—์„œ๋Š” ์–ด๋Š ์ปดํ“จํ„ฐ์—์„œ ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ•  ์ง€ ์•Œ ์ˆ˜ ์—†dma
- desired state
๋ฅผ ์š”๊ตฌํ•  ๋ฟ์ด์ง€, ํด๋Ÿฌ์Šคํ„ฐ ์•ˆ ๋…ธ๋“œ๋“ค ์ค‘ ์–ด๋””์„œ ๋™์ž‘ํ•  ์ง€ ์•Œ ์ˆ˜ ์—†๋‹ค. IP Address ๋Œ€์‹  ๋ผ๋ฒจ์„ ์‚ฌ์šฉ
- 
๋ผ๋ฒจ๋กœ ๋ช…๋ น์ด๋‚˜ ๋ถ€ํƒ์ด ์ ์šฉ๋˜๊ธธ ๋ฐ”๋ผ๋Š” pod๋“ค์˜ ์ง‘ํ•ฉ์„ ์˜๋ฏธ (๊ทธ๋ฃจํ•‘์˜ ๊ธฐ๋Šฅ) 

 

* Kubernetes pods are mortal - pod๋„ ์ค‘๊ฐ„์ค‘๊ฐ„ ์ฃฝ์„ ์ˆ˜ ์žˆ๋‹ค / ์ˆ˜๋ช…์ด ์žˆ๋‹ค 

-> pod์„ ์ƒˆ๋กญ๊ฒŒ ๋„์›Œ์„œ desired state๋ฅผ ์œ ์ง€ํ•จ  ๋”ฐ๋ผ์„œ IP address๋Š” ์–ธ์  ๊ฐ€๋Š” ๋ฐ”๋€” ์ •๋ณด / ์ฃฝ๊ณ  ์ƒˆ๋กœ์šด ์• ๊ฐ€ ๋งŒ๋“ค์–ด์ง€๋ฉด IP๊ฐ€ ๋ฐ”๋€œ
- 
์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ํŒŸ๋“ค์ด ๋Œ€ํ™”ํ•  ๋•Œ, ๊ฐœ๋ณ„ pod์˜ ์ •๋ณด์ธ IP address๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ - ๋ผ๋ฒจ๋กœ ์ ‘๊ทผํ•จ, ์ง์ ‘ ์ ‘๊ทผํ•˜์ง€ ์•Š๋„๋ก, ์ค‘๊ฐ„์„ ๋Š์Œ

- IP๋ฅผ ์•ˆ๋‹ค? ๋ˆ„๊ฐ€ ๋ช‡ ๊ฐœ ์žˆ๋Š”์ง€ ๋นคํžˆ ์•ˆ๋‹ค - ์ด๋Ÿฐ ๊ฒฐํ•ฉ์„ฑ ์ง€์–‘
- the set of pods running in one moment in time could be different from the set of Pods running that application a moment later 

+ ์ด๊ฑธ ์šด์˜ํ•˜๋Š” ๊ฑด ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๊ฐ€ ์•Œ์•„์„œ ํ•  ๊ฒƒ์ด๋‹ค / ์„œ๋น„์Šค(node port) ์ด๋Ÿฐ ์• ๋“ค์ด ๋ฐ”๊นฅ์— ๋ถ™์Œ (ํŠธ๋ž˜ํ”ฝ์„ ๋ฐ›์Œ)
- 
์ค‘๊ฐ„์— ์žˆ๋Š” ์„œ๋น„์Šค๊ฐ€ ๋‚ด ๋’ค์— 3๊ฐœ์˜ ํŒŸ์ด ์žˆ๊ตฌ๋‚˜ -> ์‰ฌ๋Š” ์• ํ•œํ…Œ ์ผ์„ ๋” ์ค˜์•ผ์ง€ (๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ) 
- 
๋ฐ”๊นฅ์—์„œ ์•ˆ์˜ ip๋ฅผ ๋ณผ ํ•„์š” X / ์„œ๋น„์Šค๊นŒ์ง€๋งŒ ์˜ค๋ฉด ๋’ค๋กœ ์•Œ์•„์„œ ๋ณด๋ƒ„ + ์„œ๋น„์Šค๋ผ๋Š” ์•  ๋งˆ์ €๋„ ๋’ค์— ํŒŸ๋“ค์„ ๋ฐ”๋ผ๋ณผ ๋•Œ label (app:myapp)์œผ๋กœ ์ฐพ์•„์„œ, ์ ‘์†ํ•˜๋ฉด ๋œ๋‹ค / ๋’ค์— ์žˆ๋Š” ์• ๋“ค์˜ IP Address๋ฅผ ์•Œ ํ•„์š”๊ฐ€ ์—†๋‹ค -> ๋ผ๋ฒจ์„ ์”€

 

* ReplicaSet – to maintain a stable set of replica Pods running at any given time
- To guarantee the availability of a specified number of identical Pods 
- 
๋„์ปค์—์„œ๋Š” replicas ๋ช…๋ น์œผ๋กœ ๊ฐœ์ˆ˜ ์ง€์ • / ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” replica set controller์—๊ฒŒ ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ์ƒํƒœ๋ฅผ ์ „๋‹ฌํ•˜๋ฉด, 
์›ํ•˜๋Š” ๊ฐœ์ˆ˜๋งŒํผ ์•ˆ์ •์ ์œผ๋กœ ์ˆ˜ํ–‰ - Replica set ์–˜๋„ SW
- A ReplicaSet creates & delete Pods as needed to reach the desired state 
- 
์šฐ๋ฆฌ๊ฐ€ replica set controller์—๊ฒŒ ์ค„ ๋•Œ 3๊ฐ€์ง€ ์ •๋ณด๋ฅผ ์ค€๋‹ค 

1) ์ด๋Ÿฐ ํŒŸ์ด์•ผ (๊ธฐ์กด ์–ŒํŒŒ์ผ = pod template)
2) number of replica - 
์ด๊ฑธ ๋ช‡ ๊ฐœ ์‹คํ–‰ํ•ด์ฃผ์„ธ์š”

3) selector - ๋ผ๋ฒจ์„ ์ „๋‹ฌ + IP Address ๋Œ€์‹  ์…€๋ ‰ํ„ฐ๋กœ ์‹๋ณ„

+ Set-based Requirement – filtering keys according to a set of values 
ex) environment in (Production, qa) / tier notin (frontend, backend) – in, not in, exist 
๋“ฑ 
ex) kubectl get pods -l environment=production, tier=frontend           // -l 
๋ผ๋ฒจ์— ๋Œ€ํ•œ ์กฐ๊ฑด์„ ์˜๋ฏธํ•จ

 

 

 

simple-replicaset.yaml

 

 

 

* ReplicaSet์€ class์ž„ (kind๊ฐ€ ํด๋ž˜์Šค๋ฅผ ์˜๋ฏธํ•จ)
- 
์ฆ‰, ReplicaSet ๊ฐ์ฒด๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์„œ ๋„์šฐ๋Š” ๊ฒƒ๊ณผ ๋™์ผํ•œ ์˜๋ฏธ
- 
์ด๊ฒŒ simple-replicaset.yaml ์–ŒํŒŒ์ผ์˜ ์˜๋ฏธ 
-> 
๋ผ๋ฒจ์„ my-little-pod์œผ๋กœ ์ดˆ๋ก์ƒ‰์„ 3๊ฐœ ๋„์›Œ๋‹ฌ๋ผ๊ณ  rs์—๊ฒŒ ๋ถ€ํƒํ•˜๋Š” ๊ฒƒ

 

+ IP address๋Š” ๋ฌด์šฉ์ง€๋ฌผ / label์„ ์จ์•ผํ•œ๋‹ค.

* Service Distribution in ReplicaSet (Rolling) 
- 
๊ตฌ๋ฅด๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์„œ๋น„์Šค๊ฐ€ ํ•˜๋‚˜ํ•˜๋‚˜ ์ฒœ์ฒœํžˆ ๋ฐ”๊พธ๋Š” ๊ฒƒ
- 3
๊ฐœ์˜ pod์„ update ํ•˜๋ ค๋ฉด, ํ•˜๋‚˜ํ•˜๋‚˜์”ฉ ๋Š๊ณ , ์ƒˆ๋กญ๊ฒŒ ์—ฐ๊ฒฐํ•จ -> rolling update
- 
ํ•˜๋‚˜์”ฉ ๋ฐ”๊พธ๋ฉด์„œ ์ง„๋„๊ฐ€ ๋‚˜๊ฐ / ๋กค๋ฐฑ์€ ํ•˜๋‚˜์”ฉ ๋’ค๋กœ๊ฐ€๋Š” ๊ฒƒ (์›๋ณต)
- 
ํšŒ์ƒ‰์„ ํ•˜๋‚˜ ๋งŒ๋“ค๊ณ , ๋…น์ƒ‰์„ ์ง€์šด๋‹ค

 

* Apply my-replicaset 
- kubectl apply -f simple-replicaset.yaml    // 
ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ์˜ ํŒŒ์ผ์„ ํ™œ์šฉํ•˜์—ฌ 

 

 

 

Chap20. Kubernetes Objects & kubecctl Commands 

- ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ๊ณผ ์œ ์‚ฌํ•œ ๋™์ž‘
- CRUD
์˜ ๋Œ€์ƒ์ด ๋ฆฌ์†Œ์Šค(๊ฐ์ฒด) / restful interface๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ์†Œ์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์—…๋ฐ์ดํŠธ, ์‚ญ์ œํ•˜๋Š” ์šฉ๋„๋กœ ์‚ฌ์šฉํ•จ
- API
์˜ URL์ด ์–ด๋–ค ๋ฆฌ์†Œ์Šค, ์–ด๋–ค ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•  ๊ฒƒ์ธ์ง€๋ฅผ ์˜๋ฏธํ•จ
+ 
๋„์ปค์˜ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์€ ๋‚˜ ์Šค์Šค๋กœ -> API ํ˜ธ์ถœ์ด ํฐ ์˜๋ฏธ ์—†์—ˆ์Œ

- ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ์–ŒํŒŒ์ผor ์†์œผ๋กœ ํ•˜๋˜ ๊ฒƒ์„ restfulAPI๋ฅผ ์ •์˜ํ•˜์—ฌ ํ˜ธ์ถœํ•จ


- 
์–ŒํŒŒ์ผ ์žˆ๋˜ kind๊ฐ€ ๋ฆฌ์†Œ์Šคํƒ€์ž…์„ ์˜๋ฏธ 

- class๋กœ๋ถ€ํ„ฐ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋งŒ๋“ค์–ด์ง„๋‹ค๋Š” ๊ฒƒ์ด ๊ฐ์ฒด์ง€ํ–ฅ์˜ ์ปจ์…‰๊ณผ ๋™์ผํ•˜๋‹ค
- A resource is an object with a type, associated data, relationships to other resources, and a set of methods 
- it it similar to an object instance in an object-oriented programming language, with the important difference that only a few standard methods are defined for the resources (get post put and delete) while object instance
๋Š” ๋งŽ์Œ

 

* Record of Intent  ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์—๊ฒŒ your cluster’s desired state๋ฅผ ์ „๋‹ฌ 
- All objects have common metadata – 
์–ŒํŒŒ์ผ์„ ์˜๋ฏธ / ์šด์˜ํ•˜๋Š” ์ž…์žฅ์—์„œ๋Š” intent ๋ผ๋Š” ๋ง์„ ๋งŽ์ด ํ•œ๋‹ค
- 
๋‹ค ์ž๋™ํ™”๋ฅผ ํ•˜๋Š” ๊ฒƒ + ๋ณธ์ธ์˜ ์˜์‚ฌ(desired state)๋งŒ ๋ฐํžˆ๋Š” ๊ฒƒ

+ policy = ์กฐ๊ฑด๋ฌธ์„ ์ฃผ๋Š” ๊ฒƒ / CLI๋กœ ๋ณด๋‚ด์•ผ ํ•  ๋ช…๋ น์„ API๋กœ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ 
ex) CPU 
๋ณด๋‹ˆ๊น ๊ฐ„๋‹น๊ฐ„๋‹น, pod์„ ๋” ๋„์›Œ์•ผ๊ฒ ์–ด ๋“ฑ ์†์œผ๋กœ ํ•˜๋˜ ์ปค๋งจ๋“œ๋ผ์ธ๋“ค์„ API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž๋™ํ™” ๊ฐ€๋Šฅ 
- 
์ด๋Ÿฌํ•œ API์— ๋Œ€ํ•ด Official Kubernetes Client Libraries๊ฐ€ ์–ธ์–ด๋ณ„๋กœ ์ œ๊ณต๋จ 

- ์–ŒํŒŒ์ผ๋กœ spec์„ ๋ช…์‹œํ•œ๋‹ค  ์ด๊ฒŒ ์šฐ๋ฆฌ์˜ intent (desired state) 
- 
์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๊ฐ€ ์šด์˜ํ•˜๋Š” ์ƒํ™ฉ - status (object์˜ ์‹ค์ œ ์ƒํƒœ) / ์‹œ๊ฐ„์— ๋”ฐ๋ผ ์ƒํƒœ๊ฐ€ ๋ณ€ํ•˜๋ฉด, ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๊ฐ€ ์—…๋ฐ์ดํŠธ ํ•จ

 

* Deployment – is an object that can represent an application running on your cluster 
- replica set
์€ ๊ธฐ๋Šฅ์ , ์ฝ”๋“œ์ƒ์œผ๋กœ๋Š” kind๋งŒ ReplicaSet -> Deployment๋กœ ๋ฐ”๋€œ 
- kubectl apply -f simple-deployment.yaml 

+ 3๊ฐœ์˜ pod ์ค‘ ์–ด๋Š pod์˜ nginx๋กœ ๊ฐ€๊ณ  ์žˆ๋Š”๊ฑฐ์ง€? log ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋ณผ ์ˆ˜ ์žˆ๋‹ค
 -> load balancing 
์œผ๋กœ 3๊ฐœ์˜ pod๋“ค์ด ๋ฒˆ๊ฐˆ์•„ ๊ฐ€๋ฉด์„œ ๋‹ตํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค

+ Deployment is a higher-level concept that manages ReplicaSets and provides declarative updates to Pods along with a lot of other useful features. + Recommend using Deployments instead of directly using ReplicaSets // Deployment resource makes it easier for updating your pods to a newer version // automatically without any human interaction and increases the abstraction by one level.

 

 

 

Chap21. Dashboard
- 
ํ•„์š”ํ•œ Pod์„ ๋„์šฐ๊ณ  ๋ชจ๋‹ˆํ„ฐ๋งํ•œ ์ดํ›„, ์ƒˆ๋กœ์šด pod ๋„์šฐ๊ธฐ 

+ ๋ฒ„์ „ ์—…๊ทธ๋ ˆ์ด๋“œ, ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œ ๋“ฑ ๋‹ค์–‘ํ•œ ์ž‘์—…์„ ์ž๋™ํ™”ํ•ด์ฃผ๋Š” deployment controller (์ง€๋‚œ ์‹œ๊ฐ„) 

- ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ์›น ์„œ๋ฒ„์ฒ˜๋Ÿผ dashboard๋ฅผ ์ œ๊ณตํ•œ๋‹ค 

 ์‚ฌ๋‚ด ํŠน์ • ํ™”๋ฉด์„ ๋ณด์—ฌ์ฃผ๋Š” ๋Œ€์‹œ๋ณด๋“œ๋ฅผ ๋งŽ์ด ๊ฐœ๋ฐœ, ์˜คํ”ˆ์†Œ์Šค


- minikube dashboard (--url) 
- kubectl apply -f simple-deployment.yaml --record 

+ Pod๋“ค์ด ์ƒ์„ฑ๋˜๊ณ , ์ฃฝ๋Š” ๊ณผ์ •์„ ๋™์ ์œผ๋กœ UI๋ฅผ ํ†ตํ•ด ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. 
- pod
์„ ๊ฐ•์ œ๋กœ delete ์ฃฝ์ด๋ฉด replicaset์ด ํ•˜๋‚˜ ๋” ์‚ด๋ฆผ (desired state ์œ ์ง€ํ•˜๋ ค๊ณ ) 
- Scale Up & Down, Deployment yaml 
ํŒŒ์ผ update๋„ ๊ฐ€๋Šฅ 

 

 

 

Chap22. Services 
* Pods – mortal - 
๋‹ค์–‘ํ•œ ์ด์œ ๋กœ pod์€ ์ค‘๊ฐ„์— ์ฃฝ์„ ์ˆ˜ ์žˆ์Œ + ์ฃฝ์—ˆ๋‹ค ์‚ด์•„๋‚œ๋‹ค๊ณ  ๊ฐ™์€ ์• ๋Š” ์•„๋‹˜ (๋™์ ์ด๋‹ค)
- 
์Šค์ผ€์ผ๋ง ์—…, ๋‹ค์šด๋„ ๊ฐ€๋Šฅ + IP address๊ฐ€ ํฐ ์˜๋ฏธ ์—†์Œ 

* How do those frontends find out and keep track of which backends are in that set? 
+ 
์•ž์—์„œ ์š”๊ตฌ๋ฅผ ๋ฐ›์•„์ฃผ๋Š” pod๋“ค์ด ํ”„๋ก ํŠธ์—”๋“œ / ๋’ค์—์„œ ์ž‘์—…์„ ํ•ด์ฃผ๋Š” backend pods / ๋‹ต: ๋ผ๋ฒจ๊ณผ ์…€๋ ‰ํ„ฐ

 

* Services – an abstraction which defines a logical set of Pods and a policy by which to access them 
- 
์„œ๋น„์Šค๋ฅผ ์ œ์–ดํ•˜๊ธฐ ์œ„ํ•œ ๋ชฉ์ ์œผ๋กœ LabelSelector ์‚ฌ์šฉ – set of pods targeted by a Service is determined by LS

+ pod๋“ค์ด IP address๋ฅผ ๊ฐ–์ง€๋งŒ, ์ด๊ฑธ ๊ฐ–๊ณ  ์ž‘์—…ํ•˜์ง€๋Š” ์•Š์Œ - Cluster ๋ฐ”๊นฅ์œผ๋กœ๋Š” ์•„๋ฌด ์˜๋ฏธ๊ฐ€ ์—†์Œ 
-> 
์™ธ๋ถ€๋กœ ๋„คํŠธ์›Œํฌ์— ๊ตฌ๋ฉ์„ ๋šซ์œผ๋ ค๊ณ  ์„œ๋น„์Šค ๋„์ž… 

 

* Cluster IP Service – it is the default Kubernetes service – ์ตœ์ดˆ์˜ ์„œ๋น„์Šค
- it gives you a service inside your cluster that other apps inside your cluster can access
- 
์™ธ๋ถ€ ํ†ต์‹ ์ด ํ•„์š” ์—†๋‹ค -> only cluster IP๋งŒ ๊ฐ–๊ณ  ํ•จ / there is no external access.

 

* NodePort Service - ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๊ตฌ์„ฑํ•˜๊ณ  ์žˆ๋Š” ๋…ธ๋“œ์— ๊ตฌ๋ฉ์„ ๋šซ์–ด์„œ, ์™ธ๋ถ€์—์„œ ์•ˆ์œผ๋กœ ํŠธ๋ž˜ํ”ฝ์ด ๋“ค์–ด์˜ฌ ์ˆ˜ ์žˆ๋„๋ก 
- opens a specific port on all the Nodes and any traffic that is sent to this port is forwarded to the service. 

 

* Load Balancer Service - ๋ณ„๋„์˜ ๋ถ„๋ฆฌ๋œ ๋ฌผ๋ฆฌ์ ์ธ ์ปดํ“จํ„ฐ๊ฐ€ ์žˆ์„ ๋•Œ ์“ฐ๋Š” ์กฐ๊ธˆ ๋” ๋˜˜๋˜˜ํ•œ ๋„คํŠธ์›Œํฌ ๊ธฐ๋Šฅ์ด ์žˆ๋‹ค
- On GKE, this will spin up a Network Load Balancer that will give you a single IP address that will forward all traffic to your service (
๊ตฌ๊ธ€ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์—”์ง„ like Docker-Hub)

 

* Ingress – it is actually not a type of service 
- it sits in front of multiple services and act as a “smart router” or entrypoint into your cluster

 

 

 

- ์•ž์— ์žˆ๋Š” ์• ๋“ค์„ ๊ฐ–๊ณ  ์ง„ํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์— ํŒŒ์ผ์ด ๊ฐ„๊ฒฐํ•จ 

- ๋”ฐ๋ผ์„œ ์•ž์„  two-replicas-with-label.yaml์„ ๋จผ์ € ์‹คํ–‰ํ•˜๊ณ , ์ด ์„œ๋น„์Šค๋ฅผ ๋Œ๋ฆฌ๋Š” ๊ฒƒ
- 
๋‚ด๊ฐ€ selectํ•  ์• ๋“ค์€ app์ด eva์ธ ๊ฒƒ๋“ค ์ค‘ release๊ฐ€ west์ธ ์• ๋“ค / ๊ทธ pod ๋‘ ๊ฐœ๊ฐ€ node port ์„œ๋น„์Šค์— ์—ฐ๊ฒฐ๋จ
- NodePort: 
์™ธ๋ถ€์— ๊ณต๊ฐœ, ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋Š” port number 80์„ ์—ด์–ด์ค€๋‹ค. 

- kubectl get pod -l app=eva -l release=west - ์™ผ์ชฝ์˜ pod 2๊ฐœ
- kubectl get pod -l app=eva -l release=east - 
์˜ค๋ฅธ์ชฝ์˜ pod 2๊ฐœ

* kubectl cluster-info -> ์—ฌ๊ธฐ์„œ ์•Œ์•„๋‚ธ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์„œ๋น„์Šค์˜ IP๊ฐ€ curl ๋ช…๋ น์–ด์˜ ๋„๋ฉ”์ธ(masterIP) ์ž๋ฆฌ๋กœ ๋“ค์–ด๊ฐ
- curl 
http://192.168.64.2:30658    // ๋…ธ๋“œํฌํŠธ๊ฐ€ port 80์„ 32530์— mappingํ•˜์—ฌ ์—ด์–ด๋‘ 
+ curl 
http://eva/                           // ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ด๋ฆ„, ๋ผ๋ฒจ๋กœ๋„ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค!

+ Cluser IP – Cluster IP isn’t accessible from outside of the Kubernetes cluster. This is an internal IP only meaning that other pods can use a Services Cluster IP to communicate between them but we can’t just put this IP address in our web browser and expect to get connected to the service in our Kubernetes cluster. 

+ NodePort – A NodePort exposes a service on each node’s IP address on a specific port. 
- NodePort doesn’t replace ClusterIP however, all it does is direct traffic to the ClusterIP from Outside the cluster.
- NodePort must be within the port range 30000-32767

 

 

 

Chap23. Images and Registries
- 
์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์ด๋ฏธ์ง€๋Š” ๋„์ปค์™€ ๋™์ผํ•œ ์ด๋ฏธ์ง€ - ์ด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ pod์„ ์‹คํ–‰ํ•œ๋‹ค
- you need to push it to a registry before referring to it in a Kubernetes pod 
+ The default pull policy is IfNotPresent which causes the kublet to skip pulling an image if it already exists 

* ImagePullPolicy


1) IfNotPresent – the image is pulled only if it is not already present locally - 
๋ณธ์ธ์˜ ๋กœ์ปฌ์— ์—†๋‹ค๋ฉด ๊ฐ€์ ธ์˜ค๋Š” ์ •์ฑ…
2) Always – the image is pulled every time the pod is started - 
๋ณธ์ธ์˜ ๋กœ์ปฌ์— ์žˆ๋˜ ์—†๋˜ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ
3) Never – the image is assumed to exist locally – No attempt is made to pull the image 

 

* Why You Should Avoid :latest tag - immutable vs muttable 
- 
๋ฒ„์ „์ด ๊ณ ์ •๋˜์—ˆ๋‹ค๋ฉด ์ข‹๊ฒ ๋‹ค (immutable) - ํ•˜๋‚˜์˜ ๋ฒ„์ „์ด ๋ช…์‹œ์ ์œผ๋กœ ์šด์˜ / latest๋ผ๋ฉด 1๊ณผ 2๊ฐ€ ํ˜ผ์šฉ๋  ์šฐ๋ ค์ 
-> 
๋ฒ„์ „ ํŠธ๋ž™ํ‚น์˜ ์—๋Ÿฌ์‚ฌํ•ญ์ด ์žˆ์œผ๋‹ˆ, ์ •ํ™•ํžˆ ๋ฒ„์ „์„ ๋ช…์‹œํ•˜์ž (latest ๋ง๊ณ ) 

 

* ์ƒ์šฉ ์„œ๋น„์Šค์— ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ registry – public cloud provider๋“ค์ด ์ œ๊ณตํ•˜๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค registry๋“ค
- 
์•„๋งˆ์กด์˜ ECR – Elastic Container Registry / EKS - ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์„œ๋น„์Šค
- MS Azure Container Registry / IBM Cloud Container Registry / Google Container Registry – gcr 
์ƒ˜ํ”Œ๋“ค ๋งŽ์Œ

 

 

 

Chap24. Scale and Rolling Updates 
- pod
์˜ ์ˆ˜๋ฅผ ๋Š˜๋ฆฌ๊ณ , ์ค„์ด๋Š” Scale / ๋ฒ„์ „ ์—…๋ฐ์ดํŠธ์™€ ๊ด€๋ จ๋œ Rolling / ์ด๋ก ์€ ๋ณต์žกํ•˜์ง€๋งŒ, ๋ช…๋ น์€ ๋งค์šฐ ๊ฐ„๋‹จ

* Scaling  ํŠธ๋ž˜ํ”ฝ์ด ์ฆ๊ฐ€ํ•˜๋ฉด, deployment์˜ replicas ์ˆ˜๋ฅผ ๋ฐ”๊พผ๋‹ค 
- 
ํ•˜๋‚˜์˜ pod์œผ๋กœ ๊ตฌ์„ฑ๋œ ์„œ๋น„์Šค A์— 3๊ฐœ์˜ Pod๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ scaling up + ๋…ธ๋“œ๋„ 2๊ฐœ ๋” ์ถ”๊ฐ€๋œ ์ƒํ™ฉ 
- 
์—ญ์œผ๋กœ ์ง„ํ–‰๋˜๋Š” ์˜ค๋ฅธ์ชฝ์—์„œ ์™ผ์ชฝ์ด scaling down (pod์˜ ์ˆ˜๋ฅผ ์ค„์ด๋Š” ๊ฒƒ)

 

* Rolling Updates – deployments’ update to take place zero downtime by incrementally updating pods instances with new ones –> updates can be reverted to previous version – pod์˜ ์ˆ˜๊ฐ€ ์•„๋‹ˆ๋ผ ์„ฑ์งˆ(๋ฒ„์ „)์ด ๋ณ€ํ•˜๋Š” ๊ฒƒ!
- 
๋ฒ„์ „์ด ๋ฐ”๋€Œ๋Š” ๊ฒƒ์ด ๋‹ฌ๋ผ์ง (์ดˆ๋ก์ƒ‰ -> ๋ณด๋ผ์ƒ‰์œผ๋กœ ํ•˜๋‚˜ํ•˜๋‚˜ ๊ต์ฒด) 

- ์ดˆ๋ก ๋ฒ„์ „์œผ๋กœ ๋Œ์•„๊ฐ€๋Š” 4๊ฐœ์˜ pod์„ ๋ณด๋ผ์ƒ‰ ๋ฒ„์ „์œผ๋กœ ๋ฐ”๊พธ๊ณ  ์‹ถ๋‹ค 
- immutable (
๋™์ผํ•œ ๋ฒ„์ „)์— ๋Œ€ํ•œ ์ค‘๊ฐ„ ๊ณผ์ •์ด ์žˆ์Œ - final์—์„œ๋Š” ๋ชจ๋‘ ๋ณด๋ผ์ƒ‰์œผ๋กœ ๋ณ€ํ™”ํ•จ (smooth)
- 
์™ธ๋ถ€ IP๋Š” ๋ณ€ํ™” X // ๋‚ด๋ถ€ IP๋Š” ๋ชจ๋‘ ๋ฐ”๋€œ! 

 

* Scaling & Rolling Updates ์‹ค์Šต
- kubectl scale deployments/Kubernetes-bootcamp --replicas=2         // scaling
- kubectl set image deployments/Kubernetes-bootcamp kubernetes-bootcamp=jocatalin/Kubernetes-bootcamp:v2
-> 
๋ช…๋ น์–ด ํ•œ ์ค„์ด์ง€๋งŒ, ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๊ฐ€ ๋งŽ์€ ์ผ๋“ค์„ ํ•œ๋‹ค – image์˜ ๋ฒ„์ „์„ ๊ตฌ๊ธ€ -> ์กฐ์บํ‹€๋ฆฐ์œผ๋กœ ๋ฐ”๊พผ๋‹ค๋Š” ์˜๋ฏธ 


- Rolling - 
์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ฆ, ๊ธฐ์กด ์ด๋ฏธ์ง€ pod๋ฅผ ํ•˜๋‚˜ ์ฃฝ์ž„, ์ƒˆ ์ด๋ฏธ์ง€๋ฅผ ํ•˜๋‚˜ ๋Š˜๋ฆฌ๊ณ , 
๊ธฐ์กด pod ํ•˜๋‚˜ ๋” ์ฃฝ์—ฌ์„œ update๋ฅผ ๋๋‚ธ๋‹ค! curl๋กœ ๋ถ™์–ด๋ณด๋ฉด, version์ด 1์—์„œ 2๋กœ ๋ฐ”๋€ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Œ

- kubectl rollout history deployment.apps/kubernetes-bootcamp : revision์— ๋Œ€ํ•œ ์ด๋ ฅ(๋กœ๊ทธ ์ •๋ณด)์„ ๋ณผ ์ˆ˜ ์žˆ์Œ
- kubectl rollout undo deployment.apps/kubernetes-bootcamp : 
์•ž์„œ ํ–ˆ๋˜ rollout ์ž‘์—…์„ ์ทจ์†Œ์‹œํ‚จ๋‹ค roll-back
- kubectl rollout undo deployment.apps/kubernetes-bootcamp --to-revision=1 // 
ํŠน์ • ๋‹จ๊ณ„๋กœ ๋Œ์•„๊ฐ€๊ณ  ์‹ถ์œผ๋ฉด ๋ช…์‹œ

 

 

 

Chap25. Stateless and Stateful Applications 
- ์ง€๊ธˆ๊นŒ์ง€ ์šฐ๋ฆฌ๊ฐ€ ํ•œ ๊ฑด stateless – ex) ๊ฐ„๋‹จํ•œ ์›น์„œ๋ฒ„ request & response 
- stateful - 
๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์žˆ์–ด์„œ, ์ •๋ณด๊ฐ€ ์ €์žฅ๋˜์–ด์•ผ ํ•จ -> ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์žˆ๋Š” ๊ธฐ์ค€์œผ๋กœ ํ•˜๋Š” ์„œ๋น„์Šค ์˜๋ฏธ

* Stateless – doesn’t save client data generated in on session for use in the next session with that client
- there is no memory of the past - 
์„œ๋ฒ„๊ฐ€ ๊ธฐ์กด ๊ธฐ๋ก์„ ๋ฐ”ํƒ•์œผ๋กœ ํŒ๋‹จ X / ํ˜„์žฌ ์‹œ์ ์˜ ์š”์ฒญ๋งŒ์œผ๋กœ ํŒ๋‹จํ•˜๋Š” ๊ฒƒ

 

* Stateful – saves client data from the activities of one session for use in the next session 
- 
๊ณผ๊ฑฐ์˜ ์ผ, ๋ฐ์ดํ„ฐ ์ €์žฅ / ๋ณผ๋ฅจ์ด๋‚˜ ์Šคํ† ๋ฆฌ์ง€ ๋“ฑ ๋ฉ”๋ชจ๋ฆฌ / ๊ณผ๊ฑฐ ํŠธ๋žœ์žญ์…˜์˜ ์ •๋ณด๊ฐ€ ๋‚จ์•„, ํ˜„์žฌ ํŠธ๋žœ์žญ์…˜์— ์˜ํ–ฅ O 

+ stateless - rolling์— ๊ฐ•์ , ์ด๋ฏธ์ง€ update๊ฐ€ ์ž์œ ๋กœ์›€ / ๊ณผ๊ฑฐ ๋ฐ์ดํ„ฐ๊ฐ€ ์—†์œผ๋‹ˆ, ๋ฒ„์ „ ๋ณ€๊ฒฝ์— ์–ด๋ ค์›€์ด ์—†์Œ
- 
๊ณผ๊ฑฐ ์ •๋ณด์™€ ์ƒˆ๋กœ์šด ์ •๋ณด๊ฐ€ ๋…์ž์ ์œผ๋กœ ์šด์˜ ๊ฐ€๋Šฅ -> ์ง€๊ธˆ ์ƒํƒœ์— ์˜ํ•ด ๊ฒฐ์ •์ด ๋‚ด๋ ค์ง„๋‹ค.
- 
๊ธฐ์กด deployment๋ฅผ new๋กœ ๋ฎ์–ด๋ฒ„๋ฆฌ๋Š” ๊ฒƒ ex) nginx 1.14.2 -> 1.16.1 (new version) 
- kubectl apply -f 
https://k8s.io/examples/application/development-update.yaml            // ์ƒˆ ๋ฒ„์ „์œผ๋กœ ๋ฎ์ธ๋‹ค
- kubectl apply -f 
https://k8s.io/examples/application/development-scale.yaml               // replica๋งŒ 2->4 ๋ฐ”๋€œ 

 

 

 

Chap26. Storage - ๋„์ปค์™€ ๋น„์Šทํ•˜์ง€๋งŒ, k8s ๋” ๋‹ค์–‘ํ•œ ๋ณผ๋ฅจ๋“ค์ด ์žˆ๋‹ค.
(1) 
์ปจํ…Œ์ด๋„ˆ๋Š” ๋น„์ •์ƒ์ ์œผ๋กœ ์ฃฝ์—ˆ๋‹ค ์‚ด์•˜๋‹ค -> ๋ฐ์ดํ„ฐ๋Š” ์ด์™€ ๋ถ„๋ฆฌ๋˜๋„๋ก – Data persistency
(2) 
๊ฐœ๋ณ„ ์ปจํ…Œ์ด๋„ˆ๋“ค์ด file ํ˜•ํƒœ์˜ ์ •๋ณด๋ฅผ ๊ณต์œ ํ•จ -> ์ด๋ฅผ ์œ„ํ•œ ์Šคํ† ๋ฆฌ์ง€ – Shared resources 

 

* Volume -is just a directory, possibly with some data in it, which is accessible to the containers in a pod. 
- volume type - 
๋ฉ”๋ชจ๋ฆฌ, ํŒŒ์ผ ๋””์Šคํฌ์ธ์ง€ ๋” ๊ตฌ์ฒด์ ์œผ๋กœ๋Š” HDD, SSD ๋“ฑ // ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์˜ ์˜์—ญ์ด๋ผ๊ธฐ์—๋Š” ์˜ณ์ง€ ์•Š์Œ
- 
๋„์ปค ์ปจํ…Œ์ด๋„ˆ ์•ˆ์˜ ์ž„์‹œ ๊ณต๊ฐ„ : Asset(emptyDir)    // host node์˜ ํŠน์ • ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ binding : host path (Cache)

+ ์œ„ํ—˜ํ•œ ์กฐ๊ฑด - ์•ž์˜ ๋ฆฌํ€˜์ŠคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ–ˆ๋Š”๋ฐ, ๊ฑ”๊ฐ€ ์ฃฝ์–ด๋ฒ„๋ฆฌ๋ฉด? stateful? 
-> 
๋ฐ˜๋“œ์‹œ ๊ฑ” ๋ฐ”๊นฅ์— ์ €์žฅ์ด ๋˜์–ด์•ผ ํ•จ - ์ด๊ฑด ์ปจํ…Œ์ด๋„ˆ์˜ ์˜์—ญ์„ ๋ฒ—์–ด๋‚˜๋Š” ๊ฒƒ
+ 
์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์˜ ์Šคํ† ๋ฆฌ์ง€๋Š” ํ•˜๋‚˜์ž„ - persistent volume - ๋ณผ๋ฅจ์ด ํ•ญ์ƒ ์กด์žฌํ•œ๋‹ค.

 

* emptyDir – active as long as the Pod is running on that node (๋„์ปค์—์„œ์˜ volumes – ๋„์ปค ๋‚ด๋ถ€์˜ ๊ณต๊ฐ„)
* hostPath – mounts a file or directory from the host node’s filesystem into your pod (
๋„์ปค์—์„œ์˜ bind - ๋งˆ์šดํŒ…) 
* nfs – network file system - 
์Šคํ† ๋ฆฌ์ง€๋ฅผ ๋ณ„๋„๋กœ ๊ตฌ์ถ•ํ•œ ๋‹ค์Œ, ๋ฌผ๋ฆฌ์ ์œผ๋กœ ๋–จ์–ด์ง„ ์• ๋“ค์„ ๋…ผ๋ฆฌ์ ์œผ๋กœ ์—ฐ๊ฒฐํ•ด์„œ ์‚ฌ์šฉํ•จ
* PersistentVolumeClaim & PersistentVolume – a piece of storage in a Kubernetes cluster. 

+ ์ œ๋Œ€๋กœ ๋œ ์„œ๋น„์Šค๋ฅผ ํ•˜๋ฉด์„œ, ์ด์ „ ๊ณ ๊ฐ ๊ธฐ์–ตํ•˜๊ณ , ํ˜„์žฌ์„œ๋น„์Šค ํ•˜๋ ค๋ฉด statefulํ•˜๊ณ ์ž ํ•˜๋Š” state๋Š” ๋’ค์— ์žˆ์–ด์•ผ ํ•œ๋‹ค.
- 
๋„์ปค๋‚˜ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์˜ ์˜์—ญ์ด ์•„๋‹Œ, ์ œ3์˜ ๊ณต๊ฐ„์— ์กด์žฌ -> public cloud ์ „๋ฌธํ™”๋œ ์Šคํ† ๋ฆฌ์ง€ ๊ธฐ์ˆ  (๊ตฌ๊ธ€, ์•„๋งˆ์กด, MS)
- DB 
๊นจ์ง€๋ฉด ์žฅ๋‚œ ์•„๋‹˜, 2์ค‘ 3์ค‘์œผ๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ๊ธฐ์ˆ  -> ์‰ฝ์ง€ ์•Š์Œ or ๋ณธ์ธ์˜ ์ „์šฉ ํŒŒ์ผ ์„œ๋ฒ„๋ฅผ ์—ฐ๊ฒฐํ•˜๋Š” ๊ธฐ์ˆ  (nfs)

 

* PersistentVolumeClaim & PersistentVolume – PV & PVC 

1) NFS - network file system
: F 
๋””๋ ‰ํ† ๋ฆฌ ๊ฐ™์€๊ฒŒ ์ƒ๊น€ - ๋งˆ์น˜ ๋‚ด ๋ฌผ๋ฆฌ์ ์ธ ๋””์Šคํฌ๊ฐ™์ง€๋งŒ, ์‹ค์ œ๋กœ๋Š” ๋„คํŠธ์›Œํฌ๋ฅผ ํ†ตํ•ด read write ํ•˜๋Š” ๊ฒƒ
- like Remote Procedure Call (RPC)
- Cluster Admin
์ด NFS์„ ๊ตฌ์ถ•ํ•จ

(2) ๋ฌผ๋ฆฌ์ ์ธ node or cloud storage๋ฅผ ์“ธ ์ˆ˜ ์žˆ๋Š” ํ˜•ํƒœ๋กœ, ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์•ˆ์œผ๋กœ ๋Œ์–ด๋“ค์ธ๋‹ค - admin(์šด์˜ํŒ€)์ด ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์— ์ •์˜๋œ ํ˜•์‹์œผ๋กœ PV๋ฅผ ๋งŒ๋“ ๋‹ค. 
(3) User
๊ฐ€ PVC๋ฅผ create – ์ž๊ธฐ๊ฐ€ ๋งŒ๋“ค๊ณ  ์‹ถ์€๊ฑฐ ์ด์•ผ๊ธฐํ•˜๋ฉด ๋จ 
(4) 
์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์— PV๋ฆฌ์ŠคํŠธ ์ญ‰ ๋œธ - ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๊ฐ€ ์ ์ ˆํ•œ PV๋ฅผ ์‚ฌ์šฉ์ž์—๊ฒŒ bind ์‹œ์ผœ์ค€๋‹ค. (bind PVC to PV)
(5)
 pod์—์„œ volume ํ‚ค์›Œ๋“œ๋กœ ์ ‘๊ทผํ•˜์—ฌ ์“ฐ๋ฉด ๋จ – User creates a pod with a volume referencing the PVC

+ Wrap-up – 10๋งŒ ์ปจํ…Œ์ด๋„ˆ ์–‘๋ณ‘๋ก 
- 10
๋งŒ ๊ฐœ์˜ Container๋ฅผ ์•ˆ์ •์ ์œผ๋กœ ์„œ๋น„์Šค ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋ฐ˜์„ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค (Cloud Native ํ™˜๊ฒฝ)