๐ŸŒฑ ์ธํ”„๋Ÿฐ/โš“ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์–ด๋‚˜๋” ํด๋ž˜์Šค (์ง€์ƒํŽธ)

[๋ฏธ์…˜2] Application ๊ธฐ๋Šฅ์œผ๋กœ ์ดํ•ดํ•˜๊ธฐ - Probe > ์‘์šฉ๊ณผ์ œ

mallin 2025. 6. 8. 16:43

โ–ถ ์‘์šฉ ๊ณผ์ œ 1

startupProbe๊ฐ€ ์‹คํŒจ ๋˜๋„๋ก ์„ค์ •ํ•ด์„œ Pod๊ฐ€ ๋ฌดํ•œ ์žฌ๊ธฐ๋™ ์ƒํƒœ๊ฐ€ ๋˜๋„๋ก ์„ค์ •ํ•ด ๋ณด์„ธ์š”.
(์—ฌ๋Ÿฌ๋ถ„๋“ค์ด ๊ฐ€์žฅ ๋งŽ์ด ๊ฒช๊ฒŒ๋  Pod ์—๋Ÿฌ์ž…๋‹ˆ๋‹ค)

 

๊ธฐ์กด Deployment ์˜ startupProbe

startupProbe:
	httpGet:
		path: /ready
		port: http
		scheme: HTTP
	timeoutSeconds: 1
	periodSeconds: 10
	successThreshold: 1
	failureThreshold: 20

 

  • timeoutSeconds : ํ”„๋กœ๋ธŒ ์š”์ฒญ์˜ ํƒ€์ž„์•„์›ƒ ์‹œ๊ฐ„
  • periodSeconds : ํ”„๋กœ๋ธŒ ์š”์ฒญ ์‹œ๊ฐ„
  • successThreshold : ๋ช‡ ๋ฒˆ ์„ฑ๊ณตํ–ˆ์„ ๋•Œ ์„ฑ๊ณต์œผ๋กœ ๊ฐ„์ฃผํ• ์ง€
  • failureThreshole : ๋ช‡ ๋ฒˆ ์‹คํŒจ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆด์ง€

 

์‹ค์ œ Pod ์˜ ๋กœ๊ทธ๋ฅผ ๋ณด๋ฉด startUpProbe ๊ฐ€ 4๋ฒˆ ์‹คํŒจํ•˜๊ณ , 5๋ฒˆ์งธ์—์„œ ์„ฑ๊ณต !!

=> failureThreshole ๋ฅผ ๋‚ฎ์ถฐ์„œ 1๋ฒˆ์œผ๋กœ ๋‚ฎ์ถฐ์„œ ์‹คํŒจํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ

 

startupProbe:
	httpGet:
		path: /ready
		port: http
		scheme: HTTP
	timeoutSeconds: 1
	periodSeconds: 10
	successThreshold: 1
	failureThreshold: 1

 

pod๊ฐ€ CrashLoopBackOff ์ƒํƒœ๋กœ ๊ณ„์† restart ๋จ

๐Ÿ’ฅCrashLoopBackoff ์ƒํƒœ๋Š” Kubernetes์—์„œ Pod๊ฐ€ ๊ณ„์†ํ•ด์„œ ํฌ๋ž˜์‹œ(์ถฉ๋Œ)๋˜๊ณ  ์ž๋™์œผ๋กœ ์žฌ์‹œ์ž‘๋˜์ง€๋งŒ, ์ผ์ • ํšŸ์ˆ˜ ์ด์ƒ ์‹คํŒจํ•˜๋ฉด์„œ ์žฌ์‹œ์ž‘ ๊ฐ„๊ฒฉ์„ ์ ์  ๋Š˜๋ ค๊ฐ€๋Š” ์ƒํƒœ


โ–ถ ์‘์šฉ ๊ณผ์ œ 2

์ผ์‹œ์  ์žฅ์•  ์ƒํ™ฉ(App ๋‚ด๋ถ€ ๋ถ€ํ•˜ ์ฆ๊ฐ€)๊ฐ€ ์‹œ์ž‘ ๋œ ํ›„, 30์ดˆ ๋’ค์— ํŠธ๋ž˜ํ”ฝ์ด ์ค‘๋‹จ๋˜๊ณ ,
3๋ถ„ ๋’ค์—๋Š” App์ด ์žฌ๊ธฐ๋™ ๋˜๋„๋ก ์„ค์ •ํ•ด ๋ณด์„ธ์š”.
(์•„๋ž˜ API๋ฅผ ๋‚ ๋ฆฌ๋ฉด readinessProbe์™€ livenessProbe๊ฐ€ ๋™์‹œ์— ์‹คํŒจํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค)

// ๋ถ€ํ•˜ ์ฆ๊ฐ€ API
curl http://192.168.56.30:31231/server-load-on
// ์™ธ๋ถ€ API ์‹คํŒจ
curl http://192.168.56.30:31231/hello
// ๋ถ€ํ•˜ ๊ฐ์†Œ API 
curl http://192.168.56.30:31231/server-load-off

 

๋ฌธ์ œ

๋ถ€ํ•˜๊ฐ€ ์ƒ๊ธด ํ›„ 

  • 30์ดˆ ํ›„ ํŠธ๋ž˜ํ”ฝ ์ค‘๋‹จ (readliness ์‹คํŒจ)
  • 3๋ถ„ ํ›„ ์•ฑ ์žฌ์‹œ์ž‘  (liveness ์‹คํŒจ)
์‹œ๊ฐ„  ๋™์ž‘ ํ•ด๋‹น probe
0์ดˆ ๋ถ€ํ•˜ ์‹œ์ž‘ readiness + liveness ์‹คํŒจ
30์ดˆ ์„œ๋น„์Šค ์ œ์™ธ readliness ์‹คํŒจ 3ํšŒ -> 10์ดˆ ๊ฐ„๊ฒฉ -> 30์ดˆ ์†Œ์š”
3๋ถ„ ์•ฑ ์žฌ์‹œ์ž‘ livenessProbe ์‹คํŒจ 3ํšŒ -> 60์ดˆ ๊ฐ„๊ฒฉ -> 3๋ถ„ ์†Œ์š”

 

 

๊ธฐ์กด ์ฝ”๋“œ

livenessProbe:
  httpGet:
    path: /ready
    port: http
    scheme: HTTP
  timeoutSeconds: 1
  periodSeconds: 10
  successThreshold: 1
  failureThreshold: 3
readinessProbe:
  httpGet:
    path: /ready
    port: http
    scheme: HTTP
  timeoutSeconds: 1
  periodSeconds: 10
  successThreshold: 1
  failureThreshold: 3
startupProbe:
  httpGet:
    path: /ready
    port: http
    scheme: HTTP
  timeoutSeconds: 1
  periodSeconds: 10
  successThreshold: 1
  failureThreshold: 10

 

  • ํ˜„์žฌ ์„ค์ •๋œ readinessProbe ๋Š” 10 * 3 = 30์ดˆ
  • ํ˜„์žฌ ์„ค์ •๋œ livenessProbe ๋Š” 10 * 30 = 30์ดˆ

-> livenessProbe ๊ฐ€ 3๋ถ„์ด ๋˜์–ด์•ผํ•˜๋ฏ€๋กœ periodSeconds ๋ฅผ 60์œผ๋กœ ๋Š˜๋ฆฌ๊ธฐ

 

๋ณ€๊ฒฝ๋œ ์ฝ”๋“œ

livenessProbe:
  httpGet:
	path: /ready
	port: http
	scheme: HTTP
  timeoutSeconds: 1
  periodSeconds: 60
  successThreshold: 1
  failureThreshold: 3

 


โ–ถ ์‘์šฉ ๊ณผ์ œ 3

Secret ํŒŒ์ผ(/usr/src/myapp/datasource/postgresql-info.yaml)์ด ์กด์žฌํ•˜๋Š”์ง€ ์ฒดํฌํ•˜๋Š” readinessProbe๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์„ธ์š”.
(๊ผญ API๋ฅผ ๋‚ ๋ฆฌ๋Š” ๊ฒƒ๋งŒ์ด readinessProbe ํ™œ์šฉ์˜ ์ „๋ถ€๋Š” ์•„๋‹™๋‹ˆ๋‹ค)

 

๊ธฐ์กด ์ฝ”๋“œ

readinessProbe:
  httpGet:
	path: /ready
	port: http
	scheme: HTTP
  timeoutSeconds: 1
  periodSeconds: 10
  successThreshold: 1
  failureThreshold: 3

 

๋ณ€๊ฒฝ๋œ ์ฝ”๋“œ

readinessProbe:
  exec:
	command: ["cat", "/usr/src/myapp/datasource/postgresql-info.yaml"]
  timeoutSeconds: 1
  periodSeconds: 10
  successThreshold: 1
  failureThreshold: 3
  • exec ๋ผ๋Š” ์†์„ฑ์œผ๋กœ command ๋ฅผ Pod ์— ๋‚ ๋ฆด ์ˆ˜ ์žˆ๋‹ค
  • App ๊ธฐ๋™์‹œ ํ•„์š”ํ•œ ํŒŒ์ผ์ด ์žˆ๋Š”์ง€ ์ฒดํฌ