liveness probe 실습

2023. 10. 27. 11:55k8s

참고 사이트

Configure Liveness, Readiness and Startup Probes | Kubernetes

 

Configure Liveness, Readiness and Startup Probes

This page shows how to configure liveness, readiness and startup probes for containers. The kubelet uses liveness probes to know when to restart a container. For example, liveness probes could catch a deadlock, where an application is running, but unable t

kubernetes.io

 

 

명령으로 liveness 정의
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

30초 후 /tmp/healthy 없는 것 확인되고 파드가 재시작 됨

 

 

http 요청으로 liveness 정의
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

시간이 지난 후 'kubectl describe liveness-http'을 통해 500코드 확인

 

파드 재시작 됨

'k8s' 카테고리의 다른 글

라벨 실습  (0) 2023.10.27
라벨  (1) 2023.10.27
hostpath  (0) 2023.10.27
empty-dir  (0) 2023.10.27
배포명세서 실습  (0) 2023.10.26