전공공부
[K8S - CKA] initContainers 본문
InitContainers
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app.kubernetes.io/name: MyApp
spec:
containers:
- name: myapp-container
image: busybox:1.28
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
initContainers:
- name: init-myservice
image: busybox:1.28
command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"]
- name: init-mydb
image: busybox:1.28
command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]
최초 한 번 실행되고 사용이 끝나는 컨테이너
(공식 문서의 설명 : 초기화 컨테이너는 파드의 앱 컨테이너들이 실행되기 전에 실행되는 특수한 컨테이너이다. 초기화 컨테이너는 앱 이미지에는 없는 유틸리티 또는 설정 스크립트 등을 포함할 수 있다. )
만일 최초 한 번 실행이 될 때 제대로 실행 되지 않으면 POD는 계속해서 initContainer가 실행이 될 때 까지 시도함
Liveness Probe & Readness Probe
Liveness Probe는 Pod health Check 진행 중 실패 상태가 뜨면 pod 재배포를 하고 Readiness Probe의 경우에는 pod 자체를 배제하고 나머지 pod로 운용 진행
apiVersion: apps/v1
kind: Deployment
metadata:
name: k8s-probes
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
livenessProbe:
initialDelaySeconds: 1 #처음 러닝시 딜레이시간
periodSeconds: 2 #2초 주기로 실행
timeoutSeconds: 1 #timeout 처리 될 시간
successThreshold: 1 # 연속으로 성공해야 할 횟수
failureThreshold: 1 # 연속으로 실패하면 이때 부터 fail
httpGet: #http의 Get 요청을 하겠다는 뜻
host:
scheme: HTTP
path: /healtz #API Health 체크 할 곳
httpHeaders: #HTTP Header 값 정의
- name: Connection
value: keep-alive
port: 80
'Study > K8S' 카테고리의 다른 글
[K8S - CKA] Cluster Upgrade Process (0) | 2023.11.13 |
---|---|
[K8S - CKA] OS Upgrade (0) | 2023.11.12 |
[K8S - CKA] Multi Container Pods (0) | 2023.11.12 |
[K8S - CKA] Configure Secrets in Applications (1) | 2023.11.12 |
[K8S - CKA] Application Commands (0) | 2023.11.05 |