livenessProbe
컨테이너에서 kubelet에 의해 주기적으로 진단하여 자가 수행 할 수 있는 기능을 보겠습니다.
실행중이는 컨테이너 pod 가 응답이 없다면 (지정된 값에 따라 질의 ) pod 를 재시작 해주는 동작입니다.
successThreshold: 1 | 몇번의 성공 결과를 수신해야 성공으로 인정하는지 |
timeoutSeconds: 1 | 결과를 기다리는 시간 |
periodSeconds: 10 | 10초마다 인터발을 가지고 건강 검진하겠다 . |
failureThreshold: 3 | 10초마다 검사한 내용이 3번 실패하면 재시작 하겠다 . |
보통 pod의 spec 에 정의
httpGet probe : 지정한 IP주소 port path 에 http get 요청을 보내, 해당 컨테이너가 응답하는지 확인한다
반환 코드가 200 이 아닌 값이 나오면 오류 , 컨테이너를 다시 시작한다
tcpSocket probe : 지정된 포트에 TCP 연결을 시도 , 연결되지 않으면 컨테이너를 다시 시작한다.
exec probe: exec 명령을 전달하고 명령의 종료코드가 0이 아니면 컨테이너를 다시 시작한다.
liveness테스트
# vi pod-nginx-liveness.yaml |
apiVersion: v1 kind: Pod metadata: name: pod-nginx-liveness spec: containers: - image: nginx:1.14 name: pod-nginx ports: - containerPort: 80 protocol: TCP livenessProbe: httpGet: path: / port: 80 |
# kubectl create -f pod-nginx-liveness.yaml |
livenessProbe아래에 다른 옵션은 안주더라도
# kubectl describe pod liveness-pod 명령어로 아래 처럼 디폴트갑이 들어간걸 확인할수있으며 필요시
Liveness: http-get http://:8080/ delay=0s timeout=1s period=10s #success=1 #failure=3
# kubectl get pod liveness-pod -o yaml 명령어로 옵션들을 확인하여 넣어줄수 있습니다.
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
failureThreshold: 3
값 을 찾아서 yaml 파일에 넣어 값을 수정할 수 있습니다. 들여쓰기는 httpGet: 와 같은 라인에 맞추면됩니다.
liveness 테스트를 위해 만들어진 이미지로 테스해보겠습니다.
# vi pod-liveness.yaml |
apiVersion: v1 kind: Pod metadata: name: liveness-pod spec: containers: - image: smlinux/unhealthy name: unhealthy-containers ports: - containerPort: 8080 protocol: TCP livenessProbe: httpGet: path: / port: 8080 |
# kubectl create -f pod-liveness.yaml |
unhealthy 이미지는 50 이후부터 서버가 통신이 안되는 자동 프로그램입니다.
60초뒤에 자동으로 재시작 합니다.
어떻게 재시작 되는지 확인해보겠습니다.
# kubectl describe pod liveness-pod |
... IP: 10.101.1.69 Containers: unhealthy-containers: Container ID: cri-o://78249a85d20e864655297d3eb428ff07727747326f76225254c7a6157131d5ba Image: smlinux/unhealthy Image ID: 2b208508abf77405442664f1475d8a4fa218de28e9dec8e74d73084e23a30f75 Port: 8080/TCP Host Port: 0/TCP State: Running Started: Tue, 05 Sep 2023 14:11:24 +0900 Ready: True Restart Count: 0 Liveness: http-get http://:8080/ delay=0s timeout=1s period=10s #success=1 #failure=3 Environment: Mounts: /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-lh8kk (ro) ... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 2m16s default-scheduler Successfully assigned vittorio/liveness-pod to worker1 Normal Pulling 2m16s kubelet Pulling image "smlinux/unhealthy" Normal Pulled 99s kubelet Successfully pulled image "smlinux/unhealthy" in 36.572s (36.572s including waiting) Normal Created 99s kubelet Created container unhealthy-containers Normal Started 99s kubelet Started container unhealthy-containers Warning Unhealthy 26s (x3 over 46s) kubelet Liveness probe failed: HTTP probe failed with statuscode: 500 Normal Killing 26s kubelet Container unhealthy-containers failed liveness probe, will be restarted |
데몬이 응답이 없어 killing중인걸 확인 할 수 있습니다.
Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 2m31s default-scheduler Successfully assigned vittorio/liveness-pod to worker1 Normal Pulled 114s kubelet Successfully pulled image "smlinux/unhealthy" in 36.572s (36.572s including waiting) Warning Unhealthy 41s (x3 over 61s) kubelet Liveness probe failed: HTTP probe failed with statuscode: 500 Normal Killing 41s kubelet Container unhealthy-containers failed liveness probe, will be restarted Normal Pulling 11s (x2 over 2m31s) kubelet Pulling image "smlinux/unhealthy" Normal Created 9s (x2 over 114s) kubelet Created container unhealthy-containers Normal Started 9s (x2 over 114s) kubelet Started container unhealthy-containers Normal Pulled 9s kubelet Successfully pulled image "smlinux/unhealthy" in 1.916s (1.916s including waiting) |
다시 kubelet 을 통해 재생성되어 정상작동중인걸 확인할수있습니다.
#vi liveness-exam.yaml
apiVersion: v1
kind: Pod
metadata:
name: liveness-exam
spec:
containers:
- image: busybox
name: busybox-containers
args:
- /bin/sh
- -c
- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
livenessProbe:
'Linux&Ubuntu > Docker&kuber' 카테고리의 다른 글
static pod 만들기 (0) | 2023.09.06 |
---|---|
init container 란 (0) | 2023.09.06 |
kuberctl 명령어 (0) | 2023.09.01 |
docker_compose_vsftpd활용 (0) | 2023.08.08 |
docker 리플리케이션 master ,slave 걸기 (0) | 2023.03.28 |