Liveness Probe
- pod가 계속 실행할 수 있음을 보장
- Pod의 spec에 정의
# pod-definitaion
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx-container
image: nginx:1.14
# livenessProbe-definitaion
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx-container
image: nginx:1.14
livenessProbe:
httpGet:
path: /
port: 80
Liveness Probe 매커니즘
1. httpGet probe : 지정한 IP주소, port, path에 HTTP GET 요청을 보내, 해당 컨테이너가 응답하는지를 확인한다.
반환코드가 200이 아닌 값이 나오면 오류, 컨테이너를 다시 시작한다.
livenessProbe:
httpGet:
path: /
port: 80
2. tcpSocket probe : 지정된 포트에 TCP 연결을 시도, 연결되지 않으면 컨테이너를 다시 시작한다.
livenessProbe:
tcpSocket:
port: 22
3. exec probe : exec 명령을 전달하고 명령의 종료코드가 0이 아니면 컨테이너를 다시 시작한다.
livenessProbe:
exec :
command:
- ls
- /data/file
Liveness Probe 매개변수
- periodSecends : health check 반복 실행 시간(초)
- initialDelaySeconds : Pod 실행 후 delay할 시간(초)
- timeoutSeconds : health check 후 응답을 기다리는 시간(초)
Liveness Probe Pod 실행
# pod-nginx-liveness.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod-liveness
spec:
containers:
- name: nginx-container
image: nginx:1.14
ports:
- containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: 80
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
failureThreshold: 3
Liveness Probe Pod describe 확인
# kubectl describe pod nginx-pod-liveness
Name: nginx-pod-liveness
Namespace: default
Priority: 0
Service Account: default
Node: node2.example.com/10.100.0.102
Start Time: Sun, 27 Nov 2022 22:08:38 +0900
Labels: <none>
Annotations: <none>
Status: Running
IP: 10.44.0.1
IPs:
IP: 10.44.0.1
Containers:
nginx-container:
Container ID: containerd://81690c8a1af8a8830d8e9444fcfef73f64cc8f109c4672c8d34e02e5f495a93a
Image: nginx:1.14
Image ID: docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Sun, 27 Nov 2022 22:08:41 +0900
Ready: True
Restart Count: 0
Liveness: http-get http://:80/ delay=0s timeout=1s period=10s #success=1 #failure=3
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-df8rh (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-df8rh:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 29m default-scheduler Successfully assigned default/nginx-pod-liveness to node2.example.com
Normal Pulled 29m kubelet Container image "nginx:1.14" already present on machine
Normal Created 29m kubelet Created container nginx-container
Normal Started 29m kubelet Started container nginx-container
Liveness: http-get http://:80/ delay=0s timeout=1s period=10s #success=1 #failure=3 확인 가능
delay : running 몇 초 지난 후에 검사
timeout : 요청 후 아무 응답이 없으면 실패
period : 얼마만에 한번씩 검사
failure : 실패 횟수
success : 성공 횟수
[참고]
- https://www.youtube.com/watch?v=-NeJS7wQu_Q
'Kubernetes' 카테고리의 다른 글
[Kubernetes] Kubernetes 1.2 version 부터 Docker 사용 중단 (0) | 2022.11.30 |
---|---|
[Kubernetes] Pod - init container & infra container (0) | 2022.11.29 |
[Kubernetes] Pod 란? (0) | 2022.11.24 |
[Kubernetes] kubeadm init 실행시 unknown service runtime.v1alpha2.RuntimeService 발생 (0) | 2022.11.23 |
[Kubernetes] API version (0) | 2022.09.30 |