๐Ÿ˜‡ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค POD [๋ผ์ด๋ธŒ๋„ค์Šค, ๋ ˆ๋””๋„ค์Šค, ์Šคํƒ€ํŠธ์—… ํ”„๋กœ๋ธŒ]

๊น€์„ฑ์ธยท2023๋…„ 10์›” 11์ผ
0

[DevOps] ๐ŸณDocker & Kubernetes

๋ชฉ๋ก ๋ณด๊ธฐ
17/62
post-thumbnail

Liveness Probe

  • ์ปจํ…Œ์ด๋„ˆ ์‚ด์•˜๋Š”์ง€ ํŒ๋‹จ ํ›„ ๋‹ค์‹œ ์‹œ์ž‘ํ•˜๋Š” ๊ธฐ๋Šฅ
  • ์ปจํ…Œ์ด๋„ˆ ์ƒํƒœ๋ฅผ ์Šค์Šค๋กœ ํŒ๋‹จํ•˜์—ฌ ๊ต์ฐฉ์ƒํƒœ์— ๋น ์ง„ ์ปจํ…Œ์ด๋„ˆ ์žฌ์‹œ์ž‘

Readiness Probe

  • ํฌ๋“œ๊ฐ€ ์ค€๋น„๋œ ์ƒํƒœ์— ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ์ •์ƒ ์„œ๋น„์Šค ์‹œ์ž‘ํ•˜๋Š” ๊ธฐ๋Šฅ
  • ํฌ๋“œ๊ฐ€ ์ ์ ˆํ•˜๊ฒŒ ์ค€๋น„๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ์„ ํ•˜์ง€ ์•Š์Œ

Startup Probe

  • ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์‹œ์ž‘ ์‹œ๊ธฐํ™•์ธํ•˜์—ฌ ๊ฐ€์šฉ์„ฑ์„ ๋†’์ด๋Š” ๊ธฐ๋Šฅ
  • Liveness์™€ Readiness์˜ ๊ธฐ๋Šฅ์„ ๋น„ ํ™œ์„ฑํ™”
  • ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ๋Š” ์‹œ๊ฐ„์„ ๋ฒŒ์–ด์คŒ.

https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/

Liveness

exec-liveness.yaml : ์‹คํ–‰์„ ํ†ตํ•œ ๋ผ์ด๋ธŒ๋‹ˆ์Šค
https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: registry.k8s.io/busybox
    args:
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30; rm -f /tmp/healthy; sleep 600
    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5
  • /tmp/healthy๋ผ๋Š” ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  30์ดˆ ์žˆ๋‹ค๊ฐ€ ํŒŒ์ผ์„ ์‚ญ์ œํ•˜๋Š” ๋™์ž‘
  • livenessProbe: ์‚ด์•„์žˆ๋Š”์ง€ ์ ๊ฒ€์„ ํ•ด์ฃผ๋Š” ์—ญํ• 
    • cat /tmp/healthy๋ฅผ ์‹คํ–‰
    • ๋ฆฌ๋ˆ…์Šค ํ™˜๊ฒฝ์—์„œ ์ปค๋งจ๋“œ ์‹คํ–‰ ์„ฑ๊ณต์‹œ 0 return (์ปจํ…Œ์ด๋„ˆ ์œ ์ง€)
    • ์‹คํŒจ์‹œ ๊ทธ์™ธ ๊ฐ’ return(์ปจํ…Œ์ด๋„ˆ ์žฌ์‹œ์ž‘)
    • initailDelaySeconds: ์ •์ƒ ์‹คํ–‰ ํ›„ ์‹œ์ž‘ํ•˜๊ธฐ๊นŒ์ง€ ์‹œ๊ฐ„(์ดˆ)
    • periodSeconds: ์ ๊ฒ€ ์ฃผ๊ธฐ ์‹œ๊ฐ„(์ดˆ)

http-liveness.yaml : HTTP GET์š”์ฒญ์„ ํ†ตํ•œ ๋ผ์ด๋ธŒ๋‹ˆ์Šค
https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-http-request

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-http
spec:
  containers:
  - name: liveness
    image: registry.k8s.io/liveness
    args:
    - /server
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
        httpHeaders:
        - name: Custom-Header
          value: Awesome
      initialDelaySeconds: 3
      periodSeconds: 3
  • httpGet: get๋ฉ”์„œ๋“œ๋กœ /healthz๋ผ๋Š” uri๋กœ ์š”์ฒญ์‹œ ์‘๋‹ต์ด 200์œผ๋กœ ์˜ค๋ฉด ์‚ด์•„์žˆ๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธ (200~399)

Liveness + readiness

tcp-liveness-readiness.yaml
https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-tcp-liveness-probe

apiVersion: v1
kind: Pod
metadata:
  name: goproxy
  labels:
    app: goproxy
spec:
  containers:
  - name: goproxy
    image: registry.k8s.io/goproxy:0.1
    ports:
    - containerPort: 8080
    readinessProbe:
      tcpSocket:
        port: 8080
      initialDelaySeconds: 15
      periodSeconds: 10
    livenessProbe:
      tcpSocket:
        port: 8080
      initialDelaySeconds: 15
      periodSeconds: 10
  • readiness : TCP ์—ฐ๊ฒฐ ํ™•์ธ์„ ํ†ตํ•ด์„œ ์‚ด์•„์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธ
    • readiness ํ”„๋กœ๋ธŒ๊ฐ€ ์ปจํ…Œ์ด๋„ˆ ์‹œ์ž‘ 15์ดˆ ํ›„์— kubelet์„ ์ „์†ก
    • goproxy ์ปจํ…Œ์ด๋„ˆ์˜ 8080ํฌํŠธ์— ์—ฐ๊ฒฐ๋จ
    • probe ์„ฑ๊ณต ์‹œ, pod๋Š” ์ค€๋น„์ƒํƒœ๋กœ marked ๋จ (์„œ๋น„์Šค๋ฅผ ์‹œ์ž‘ํ•ด๋„ ๋˜๋Š” ์ƒํƒœ)

Startup Probe

https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-startup-probes

ports:
- name: liveness-port
  containerPort: 8080
  hostPort: 8080

livenessProbe:
  httpGet:
    path: /healthz
    port: liveness-port
  failureThreshold: 1
  periodSeconds: 10

startupProbe:
  httpGet:
    path: /healthz
    port: liveness-port
  failureThreshold: 30
  periodSeconds: 10
  • ์‹œ์ž‘ํ•  ๋•Œ๊นŒ์ง€ ์‹คํ–‰, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ๋Š” ์‹œ๊ฐ„์„ ๊ฐ€์ง
  • maximum minutes : 30 * 10 = 300s = 5min
  • Startupํ”„๋กœ๋ธŒ๊ฐ€ ์„ฑ๊ณตํ•˜๋ฉด, livenss probe๊ฐ€ container deadlocks์— ๋น ๋ฅธ ์‘๋‹ต์„ ๋ณด๋ƒ„.
  • ๋งŒ์ผ startup probe๊ฐ€ ์ ˆ๋Œ€ ์„ฑ๊ณต๋˜์ง€ ์•Š์œผ๋ฉด, ์ปจํ…Œ์ด๋„ˆ๋Š” 300์ดˆ ํ›„์— killed ๋˜๊ณ  pod์˜ restartPolicy์— ๋”ฐ๋ผ ์ข…์†๋จ.
  • Startup ํ”„๋กœ๋ธŒ ์‹คํ–‰ ๋™์•ˆ์—๋Š” livenssํ”„๋กœ๋ธŒ ์‹คํ–‰ ๋˜์ง€ ์•Š๊ณ ์žˆ์Œ.
    (StartUp ํ”„๋กœ๋ธŒ์˜ ์„ฑ๊ณตํ™•์ธ ํ›„ ์˜ฌ๋ฐ”๋ฅธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰์„ ํ™•์ธํ›„ liveness ๋ฅผ ํ†ตํ•ด ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰ ์ƒํƒœ๋ฅผ ํ™•์ธ)

์‹คํ–‰

kubectl create -f <Probe์ž‘์„ฑํŒŒ์ผ.yaml>
ex) kubectl create -f exec-liveness.yaml

kubectl describe pod <pod ์ด๋ฆ„>

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