티스토리 뷰

Kubernetes

deployment livenessProbe, readinessProbe

파미페럿 2024. 2. 23. 18:47

서버 개발을 하다보면 k8s를 진짜 많이 사용한다.

그 중 deploeyment 상태 체크에 쓰이는 설정인 livenessProbe, readinessProbe를 쓰긴 쓰는데 정확히 무엇인지 헷갈려 정리를 해보려 한다.

 

livenessProbe와 readinessProbe는 둘 다 pod의 상태를 체크하고 일반적으로 둘 다 같은 endpoint를 통해 체크를 하지만 언제 체크를 하느냐의 차이가 있다.

 

livenessProbe

live라는 용어에서 알 수 있듯이 pod가 현재 실행 중이고 잘 돌아가고 있을 때 pod에 문제가 생긴 것(교착 상태 등)을 감지해 pod를 재시작 하는 경우의 그 pod에 문제가 생긴 것을 어떻게 감지 할 것인가에 대한 설정이다.

 

readinessProbe

readiness, 즉 ready에 대해 체크하는 설정으로 해당 pod가 트래픽을 받을 수 있는 상태인지 체크하기 위한 설정이다.

즉, pod가 아직 pending 상태일 때(Running 상태 X) 일 때 사용되는 설정이다.

 

설정

livenessProbe, readinessProbe 둘 다 시점만 다르지 pod의 상태를 체크하는 설정이라 그런지 설정 하는 방법 또한 동일하다.

둘 다 httpGet, tcp, grpc, command 방식으로 설정이 가능하며 몇 번 시도할 것인지에 대한 설정도 가능하다.

 

아래는 httpGet으로 설정한 예로 아래와 같이 Deployment의 containers 안에 설정을 하면 된다.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-deployment
spec:
    spec:
      containers:
      - image: test-image
        name: test-api
        ports:
        - containerPort: 8080
        livenessProbe:
          httpGet:
            path: /health-check
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 3
          periodSeconds: 3
        readinessProbe:
          failureThreshold: 30
          httpGet:
            path: /health-check
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 3
          periodSeconds: 3

 

httpGet

pod 내 application에 http get request를 보내 이상이 있는지 체크하는 방법이다.

나의 경우 rest api를 제공하는 서버를 pod로 띄운 것이라서 healthCheck 할 수 있는 api 하나를 서버에 만들고 그걸로 livenessProbe, readinessProbe 설정을 했다.

livenessProbe:
	httpGet:
		path: /health-check
		port: 8080
		scheme: HTTP
	initialDelaySeconds: 3
	periodSeconds: 3

 

 

tcp

pod에 특정 port에 대한 소켓을 여는 것을 통해 이상이 있는지 체크하는 방법이다.

livenessProbe:
	tcpSocket:
		port: 8080
	initialDelaySeconds: 3
	periodSeconds: 3

 

 

grpc

pod 내 application이 gRPC Health Check Protocol을 사용한다면 사용할 수 있는 체크 방법이다.

gRPC를 잘 사용해보지 않아서 정확한건 모르지만 해당 application이 gRPC를 사용할 수 있는지 체크하는 방법이라고 한다.

gRPC health check protocol에 맞도록 request, response 등 rpc 설정을 서버에 해야 한다.

https://github.com/grpc/grpc/blob/master/doc/health-checking.md

livenessProbe:
	grpc:
		port: 8080
	initialDelaySeconds: 3
	periodSeconds: 3

 

 

command

pod에 특정 command를 실행해 이상이 있는지 체크하는 방법이다.

livenessProbe:
	exec:
		command:
        	- cat
           	- /tmp/healthy
	initialDelaySeconds: 3
	periodSeconds: 3

 

 

그 밖의 설정들

어떻게 체크할 것인지 방법 외에 probe에 대해 몇 번 체크할 것인지 텀은 어떻게 둘 것인지에 대한 설정도 할 수 있다.

 

timeoutSeconds

default는 1초로 1초 이상으로 설정 가능하다.

 

initialDelaySeconds

readinessProbe 설정에 유효한 값으로 pod가 시작되고 얼마나 기다렸다가 상태를 체크할지에 대한 설정이다.

default는 0초이다.

 

periodSeconds

probe를 시도하는데 그 사이 텀으로 default는 1초이다.

 

successThreshold

몇 번 성공해야 pod의 상태가 괜찮은거라고 간주할지에 대한 설정이다.

default는 1회이다.

 

failureThreshold

몇 번 실패해야 pod의 상태가 안 좋은 거라고 간주할지에 대한 설정이다.

default는 3이다.

 

terminationGracePeriodSeconds

prob로 pod의 상태를 체크했는데 pod의 상태가 나쁠 경우 해당 pod가 종료 되는데, 강제 종료되기까지의 유예 시간을 설정할 수 있다. default는 30초로 최소 값은 1초이다.

deployment 자체에 terminationGracePeriodSeconds를 설정할 수 있는데 deployment랑 probe 둘 다 설정되어 있을 경우 probe 결과 종료될 때는 probe의 terminationGracePeriodSeconds로 동작한다.

 

 

 

 

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

반응형

'Kubernetes' 카테고리의 다른 글

k8s 기본 구조  (0) 2024.03.10
mac Docker 설치하고 예제 앱 이미지 올리고 실행시켜보기  (0) 2022.04.20
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함