1. Probe
- 컨테이너에서 kubelet에 의해 주기적으로 수행되는 진단
- kubelet은 컨테이너에 의해 구현된 핸들러를 호출
- Probe Type
1) ExecAction
: 컨테이너 내에 지정된 명령어(Shell Command)를 실행하며, 명령어 Status Code가 0으로 종료되면 진단 성공으로 간주
exec-liveness.yaml docs/tasks/configure-pod-container
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-exec
spec:
containers:
- name: liveness
image: k8s.gcr.io/busybox
agrs:
- /bin/sh
- -c
- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
2) TCPSocketAction
: 지정된 포트에서 컨테이너 IP주소에 대해 TCP 검사를 수행.
포트와 TCP Connection이 활성화되어 있으면 진단 성공으로 간주
tcp-liveness-readiness.yaml docs/tasks/configure-pod-container
apiVersion: v1
kind: Pod
metadata:
name: goproxy
labels:
app: goproxy
spec:
containers:
- name: goproxy
image: k8s.gcr.io/gorpoxy:0.1
ports:
- containerPort: 8080
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 15
periodSeconds: 20
3) HTTPGetAction
: 지정 포트 밑 경로에서 컨테이너 IP주소로 HTTP GET 요청을 수행. 응답 코드가 200~400이면 진단 성공으로 간주
http-liveness.yaml docs/tasks/configure-pod-container
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-http
spec:
containers:
- name: liveness
image: k8s.gcr.io/liveness
args:
- /server
livenessProbe:
httpGet:
path: /healthz
port: 8080
httpHeaders:
- name: X-Custom-Header
value: Awesome
initialDelaySeconds: 3
periodSeconds: 3
- Attributes of probe
1) initiallDelaySeconds : 처음부터 Liveness Probe로 Health Check를 하는 것이 아니라, 컨테이너가 구동되기까지의
대기 시간
2) periodSeconds : Health Check 주기
3) timeoutSeconds : timeout 기준 시간
4) successThreshold & failureThreashold : Check Failure에 대한 Tolerance 제공
2. Liveness probe
- Pod의 Health Check 기능 제공하며 Failure 발생 시 Pod Restart
3. Readiness probe
- Pod의 서비스 준비 여부를 판단
- Readiness Probe가 실패하면, Pod를 Restart하는 것아 이나리 Endpoint Controller가 Pod IP를 제거하고 Load
Balancer에서 라우팅을 삭제
- Initial Delay(?)의 디폴트 상태는 'Failure'이며, 만약 컨테이너가 Readiness Probe를 지원하지 않는다면
기본 상태는 'Success'이다
* Pod가 어떤 이유로 Unhealthy 상태가 되어 Service에서 제거되면, Health Check이 불가하여 Liveness Probe에 의해
Restart가 되면 무한 루프가 되므로 Pod가 서비스할 준비가 되기까지 기다리는 시간이 필요
kind: Pod
...
spec:
readinessGates:
- conditionType: "www.example.com/feature/1"
status:
conditions:
- type: Ready
status: "False"
lastProbeTime: null
lastTransitionTime: 2021-04-01T00:00:00Z
- type: "www.example.com/feature/1"
status: "False"
lastProbeTime: null
lastTransitionTime: 2021-04-01T00:00:00Z
containerStatuses:
- containerID: docker://...
ready: true
4. Startup probe
- 컨테이너 내의 Application 시작 여부를 나타냄
- 해당 Probe가 주어진 경우, 성공까지 다른 Probe는 활성화되지 않음
- Startup Probe가 실패하면, kubelet이 컨테이너를 죽이고 Restart 처리
- 서비스를 시작하는데 시간이 오래 걸리는 컨테이너가 있는 Pod에 유용
5. Configmap
- App 배포시 개발/운영 등의 팀에 따라 Configuration이 각각 다르게 저장 가능
- Key/Value의 형식으로 사용하는 경우
# kubectl create configmap [NAME] --from-literal={Key}={Value}
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: cm-deployment
spec:
.
.
spec:
containers:
- name: cm
image: gcr.io/test/cm:v1
imagePullPolicy: Always
ports:
- containerPort: 8080
env:
- name: LANGUAGE ### Configmap의 Value를 환경변수 LANGUAGE로 선언
valueForm:
configMapKeyRef:
name: hello-cm ### Configamp Name
key: language ### Value
- 파일과 디렉토리를 마운트하여 사용하는 경우
# kubectl create configmap [NAME] --from-file={Path to file}
# kubectl create configmap [NAME] --from-file={Directory name}
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: cm-file-deployment-vol
spec:
replicas: 3
minReadySeconds: 5
selector:
matchLabels:
app: cm-file-vol
template:
metadata:
name: cm-file-vol-pod
labels:
app: cm-file-vol
spec:
containers:
- name: cm-file-vol
image: gcr.io/testbox/cm-file-volume:V1
imagePullPolicy: Always
ports:
- containerPort: 8080
volumeMounts:
- name: config-profile
mountPath: /tmp/config
volumes:
- name: config-profile
configMap:
name: cm-file
6. Secret
- 용도는 Configamap과 동일하지만 Query가 불가
- API Key나 DB password 등의 보안이 필요한 설정 정보 저장
7. Reference
쿠버네티스 컴포넌트
Kubernetes Advanced Workshop
조대협의 블로그
'System Engineering > Kubernetes' 카테고리의 다른 글
7. K8s Resource / Scheduling (0) | 2021.04.05 |
---|---|
6. K8s Volume (0) | 2021.04.05 |
4. K8s Service / Ingress (0) | 2021.03.30 |
3. K8s Controller (0) | 2021.03.25 |
2. Kubernetes Architecture (1) | 2021.02.23 |