하위 태스크 1
재시작 정책 설정
restartPolicy를 Always, OnFailure, Never로 설정
Always 정책은 컨테이너가 종료되면 항상 다시 시작한다.
always-pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: always-pod
spec:
restartPolicy: Always
containers:
- name: nginx
image: nginxPod를 생성한다.
kubectl apply -f always-pod.yaml하위 태스크 2
재시작 동작 확인
각 정책에 따른 재시작 동작 확인
다음 명령어로 Pod 상태를 감시한다.
kubectl get pods -w하위 태스크 1에서 지정한 정책이 잘 작동하는지 확인하기 위해 실행 중인 Nginx 프로세스를 강제로 종료한다.
kubectl exec always-pod -- nginx -s stopPod 상태를 확인한다. 컨테이너가 재시작되는 것을 확인할 수 있다.
NAME READY STATUS RESTARTS AGE
...
always-pod 0/1 Completed 0 82s
always-pod 1/1 Running 1 (3s ago) 84s
하위 태스크 3
Liveness Probe 작성
HTTP GET, TCP Socket, Exec 타입 Probe 작성
컨테이너에 대해 헬스 체크를 수행하는 Pod를 생성한다.
liveness-pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: liveness-pod
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 10
periodSeconds: 5Pod를 생성한다.
kubectl apply -f liveness-pod.yaml하위 태스크 4
Liveness Probe 테스트
Probe 실패 시 자동 재시작 확인
Pod가 정상적으로 실행되면 장애를 발생시켜 자동 복구 기능을 확인한다.
Nginx의 기본 응답 파일 index.html을 삭제하여 404 오류를 유발한다.
kubectl exec liveness-pod -- rm /usr/share/nginx/html/index.html자동 재시작을 확인한다.
kubectl get pods liveness-pod -w결과:
liveness-pod 1/1 Running 1 (54s ago) 80s
Probe 실패 기록을 확인한다.
kubectl describe pod liveness-pod결과:
Warning Unhealthy 1s (x2 over 6s) kubelet Liveness probe failed: HTTP probe failed with statuscode: 403
하위 태스크 5
Readiness Probe 작성
준비 상태를 확인하는 Probe 작성
다음 설정은 /ready 경로가 200 상태 코드를 반환할 때만 해당 Pod를 서비스 엔드포인트에 포함시킨다.
readiness-deploy.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: readiness-deploy
spec:
replicas: 3
selector:
matchLabels:
app: readiness-test
template:
metadata:
labels:
app: readiness-test
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /ready
port: 80
initialDelaySeconds: 5
periodSeconds: 5Deployment를 생성한다.
kubectl apply -f readiness-deploy.yaml하위 태스크 6
Readiness Probe 테스트
Probe 실패 시 Service에서 제외 확인
Pod 상태를 확인한다. 모든 Pod는 Ready 상태가 되지 않는다.
kubectl get pods결과:
NAME READY STATUS RESTARTS AGE
...
readiness-deploy-5799776c88-v8qtx 0/1 Running 0 4s
readiness-deploy-5799776c88-vssc6 0/1 ContainerCreating 0 4s
readiness-deploy-5799776c88-xp4rg 0/1 ContainerCreating 0 4s
한 Pod에 접속해 /ready 경로에 해당하는 파일을 생성한다.
kubectl exec readiness-deploy-5799776c88-v8qtx -- touch /usr/share/nginx/html/readyPod 상태를 다시 확인한다. 파일이 생성된 Pod의 READY 열이 1/1로 바뀐 것을 볼 수 있다.
kubectl get pods결과:
NAME READY STATUS RESTARTS AGE
...
readiness-deploy-5799776c88-v8qtx 1/1 Running 0 2m2s
하위 태스크 7 ~ 8
Startup Probe 작성
시작 시간이 긴 파드를 위한 Startup Probe 작성
Probe 타이밍 설정
initialDelaySeconds, periodSeconds 등 설정
startup-pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: startup-pod
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
startupProbe:
httpGet:
path: /
port: 80
failureThreshold: 30
periodSeconds: 10
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5failureThreshold: 30: Probe가 30번 실패할 때까지 기다린다.periodSeconds: 10: 10초 간격으로 체크한다.initialDelaySeconds: 5: Startup Probe가 성공한 뒤, Liveness Probe가 시작되기 전 5초간 대기한다.
Pod를 생성한다.
kubectl apply -f startup-pod.yaml하위 태스크 9 ~ 10
Init Container 작성
초기화 작업을 수행하는 Init Container 작성
Init Container 동작 확인
Init Container 완료 후 메인 컨테이너 시작 확인
초기화 컨테이너가 5초 동안 대기를 마친 후 메인 컨테이너가 실행되도록 한다.
init-pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: init-pod
spec:
containers:
- name: main-container
image: nginx
initContainers:
- name: init-myservice
image: busybox
command: ['sh', '-c', 'sleep 5; echo Init Container Done!']Pod를 생성한다.
kubectl apply -f init-pod.yamlPod 상태를 확인한다.
kubectl get pods init-pod -w결과:
NAME READY STATUS RESTARTS AGE
init-pod 0/1 Init:0/1 0 3s
init-pod 0/1 Init:0/1 0 5s
init-pod 0/1 PodInitializing 0 10s
init-pod 1/1 Running 0 12s
하위 태스크 11
사이드카 패턴 작성
로그 수집 등 보조 기능을 하는 사이드카 작성
sidecar-pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: sidecar-pod
spec:
containers:
- name: main-container
image: busybox
command: ['sh', '-c', 'while true; do echo "$(date) - Middle of the Mission!" >> /var/log/app.log; sleep 5; done']
volumeMounts:
- name: log-storage
mountPath: /var/log
- name: sidecar-container
image: busybox
command: ['sh', '-c', 'tail -f /var/log/app.log']
volumeMounts:
- name: log-storage
mountPath: /var/log
volumes:
- name: log-storage
emptyDir: {}하위 태스크 12
멀티 컨테이너 볼륨 공유
같은 Pod 내 컨테이너 간 볼륨 공유 확인
Pod를 생성한다.
kubectl apply -f sidecar-pod.yaml메인 컨테이너가 /var/log/app.log에 쓰는 내용을 사이드카가 읽고 있는지 확인한다.
kubectl logs sidecar-pod -c sidecar-container결과:
Sat Apr 4 07:54:06 UTC 2026 - Middle of the Mission!
Sat Apr 4 07:54:11 UTC 2026 - Middle of the Mission!
Sat Apr 4 07:54:16 UTC 2026 - Middle of the Mission!
Sat Apr 4 07:54:21 UTC 2026 - Middle of the Mission!
Sat Apr 4 07:54:26 UTC 2026 - Middle of the Mission!