Killer Shell CKA - Application Multi Container Issue

Jmnote (토론 | 기여)님의 2025년 9월 23일 (화) 13:10 판 (→‎같이 보기)

1 개요

Killer Shell CKA - Application Multi Container Issue (Gather logs)

2 요구사항

- Deployment의 모든 컨테이너 로그를 /root/logs.log 파일에 저장 - 실패 원인 파악

3 진단

Deployment와 파드 상태를 확인한다.

controlplane:~$ kubectl -n management get deploy
NAME           READY   UP-TO-DATE   AVAILABLE   AGE
collect-data   0/2     2            0           10s
controlplane:~$ kubectl -n management get pods 
NAME                            READY   STATUS             RESTARTS      AGE
collect-data-5759c5c888-dzvfg   1/2     CrashLoopBackOff   3 (23s ago)   82s
collect-data-5759c5c888-lsbd9   1/2     CrashLoopBackOff   3 (28s ago)   82s

4 로그 수집

아래 두 방법 중 하나를 사용한다.

- 방법 A: 모든 컨테이너 로그를 한 번에 수집

controlplane:~$ kubectl -n management logs --all-containers deploy/collect-data > /root/logs.log
Found 2 pods, using pod/collect-data-5759c5c888-dzvfg

- 방법 B: 컨테이너명 별로 개별 수집 후 같은 파일에 합치기

controlplane:~$ kubectl -n management logs deploy/collect-data -c nginx  > /root/logs.log
Found 2 pods, using pod/collect-data-5759c5c888-dzvfg

controlplane:~$ kubectl -n management logs deploy/collect-data -c httpd >> /root/logs.log
Found 2 pods, using pod/collect-data-5759c5c888-dzvfg

수집 결과 확인:

controlplane:~$ ls -l /root/logs.log
-rw-r--r-- 1 root root 1530 Sep 23 04:08 /root/logs.log

controlplane:~$ tail -n 50 /root/logs.log
...
2025/09/23 04:04:28 [notice] 1#1: start worker process 33
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.0.7. Set the 'ServerName' directive globally to suppress this message
(98)Address in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs

5 원인 분석

  • 파드 안에 nginxhttpd 두 컨테이너가 모두 TCP 포트 80을 리스닝하도록 설정되어 있다.
  • 먼저 시작한 컨테이너가 80 포트를 점유하면, 나중에 시작한 컨테이너는 Address already in use 오류로 실패한다.
  • 멀티 컨테이너 파드에서는 각 컨테이너의 리스닝 포트가 충돌하지 않도록 조정해야 한다. 예:
    • 한 컨테이너는 8080, 다른 컨테이너는 80 포트 사용
    • 또는 프록시/사이드카 설계 재검토

6 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}