일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 그라파나 시각화
- livenessPorbe
- Firelens
- 쿠버네티스 컴포넌트
- EFS CSI Driver
- blue-green
- 로드밸런서 컨트롤러
- jenkins
- 그라파나 대시보드
- grafana on kubernetes
- AWS 딥레이서
- helm
- headless service
- github action 사용법
- 딥레이서 보상함수
- SAA 합격 후기
- 딥레이서
- 솔데스크
- Kubernetes
- 쿠버네티스
- Prometheus install
- EKS 클러스터
- Solution Architecture
- terraform
- Kubernets on Jenkins
- LoadBalancer Controller
- 메탈LB
- 깃허브 액션
- kubernetes 동작 원리
- Aurora cluster
mingming
kubernetes livenessProve 본문
livenessProbe definition
- Pod가 계속 실행할 수 있음을 보장
- Pod spec에 정의
nginx-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx-container
image: nginx:1.14
livenessProbe:
httpGet:
path: /
port: 80
Pod 로그 확인하기
kubectl logs nginx-pod
livenessProbe 매커니즘
- httpGet : 지정한 IP 주소 , port, path에 HTTP GET 요청을 보내 해당 컨테이너가 응답하는지 확인한다. 반환코드가 200이 아닌 값이 나오면 오류, 컨테이너를 다시 시작한다.
livenessProbe:
httpGet:
path: /
port: 80
세번 연속 응답에 실패하면 기존 컨테이너를 죽이고 다시 컨테이너를 시작한다.
- tcpSocket : 지정한 포트에 TCP 연결을 시도. 연결되지 않으면 컨테이너를 다시 시작한다.
livenessProbe:
tcpSocket:
port: 22
22번 포트로 접속 했을때 실패하면 건강하지 않다 판단하고 해당하는 컨테이너를 삭제 후 새로운 컨테이너를 실행시킨다.
- exec : exec 명령을 전달하고 명령의 종료코드가 0이 아니면 컨테이너를 다시 시작한다.
livenessProbe:
exec:
command:
- ls
- /data/file
특정 컨테이너가 파드 기반으로 서비스하는데 백엔드에 있는 데이터베이스에서 특정 데이터를 가져와서 서비스해주는 파드이다. 따라서 파드안에 특정 데이터가 있는지 확인해보겠다. 할때 사용할 수 있음
파드를 삭제하는 것이 아닌 컨테이너를 삭제 후 재시작하는 개념이다. 따라서 ip는 바뀌지 않습니다.
livenessProbe 매개변수
- periodSeconds: health check 반복 실행 시간
- initialDelaySeconds: Pod 실행 후 delay할 시간
- timeoutSeconds: health check 후 응답을 기다리는 시간
nginx-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx-container
image: nginx:1.14
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 15
periodSeconds: 20
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 3
timeout=1s : 1초 기다리고 응답이 없으면 실패로 보겠다
period=10s : 10초 주기로 HTTP GET Probe 요청을 하겠다.
success=1 : 1번의 성공을 성공으로 간주하겠다.
failure=3 : 3번의 실패를 실패로 간주하겠다.
yaml 형식으로 템플릿 내보내기
kubectl get pods nginx-pod -o yaml
manifest 파일을 어떻게 작성해야할지 어떤 속성값을 사용할 수 있는지 확인할 수 있습니다.
spec:
containers:
- image: nginx:1.14
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /
port: 80
scheme: HTTP
periodSeconds: 10 # 수정안됨 왜인진 모름
successThreshold: 1
timeoutSeconds: 1
기존 실행중인 파드에 수정 후 재배포 해봤을 때 정상적으로 수정되지 않았습니다. 수정할 수 없는 항목이 포함되어있다는 오류가 나왔는데요, periodSeconds 는 수정이 되지 않는 것 같았습니다.
smlinux/unhealthy
처음 다섯번은 200번 코드 반환 후 500번 코드 반환하는 컨테이너 이미지 입니다.
apiVersion: v1
kind: Pod
metadata:
name: liveness-pod
spec:
containers:
- name: unhealty-container
image: smlinux/unhealthy
ports:
- containerPort: 8080
protocol: TCP
livenessProbe:
httpGet:
path: /
port: 8080
periodSeconds: 10
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 1
로그 확인하기
watch kubectl logs liveness-pod
6번의 응답 후 컨테이너 재시작
이렇게 livenessProbe를 이용해 해당 파드의 실행을 보장할 수 있습니다.
목적 : 건강한 컨테이너 서비스를 이용해보자 !
EXAMPLE
아래의 yaml 파일에 self-healing 기능을 추가하시오
- 동작되는 Pod 내의 컨테이너에 /tmp/healty 파일이 있는지 5초마다 확인한다.
- Pod 실행 후 10초 후 부터 검사한다.
- 성공횟수는 1번, 실패횟수는 연속 2회로 구성한다.
busybox.yaml
apiVersion: v1
kind: Pod
metadata:
name: liveness-exam
spec:
containers:
- name: busybox-container
image: busybox
args:
- /bin/sh
- -c
- touch /tmp/healty; sleep 30; rm -rf /tmp/healty; sleep 600
args : 컨테이너가 실행 될 때 해당 명령을 실행해라
busybox-livenessProbe.yaml
apiVersion: v1
kind: Pod
metadata:
name: liveness-exam
spec:
containers:
- name: busybox-container
image: busybox
args:
- /bin/sh
- -c
- touch /tmp/healty; sleep 30; rm -rf /tmp/healty; sleep 600
livenessProbe:
exec:
command:
- ls
- /tmp/healty
periodSeconds: 5
initialDelaySeconds: 10
successThreshold: 1
failureThreshold: 2
kubectl get pods liveness-exam -o yaml
kubectl describe pods liveness-exam
'kubernetes' 카테고리의 다른 글
kubernets Metal LB 설치하기 (0) | 2023.08.30 |
---|---|
kubernetes init container (0) | 2023.08.29 |
EKS Amazon EFS CSI Driver (helm) (1) | 2023.08.25 |
EKS AWS Load Balancer Controller (helm) (0) | 2023.08.25 |
Kubernetes 컴포넌트 (0) | 2023.08.14 |