
해당 내용은 Udemy의 Certified Kubernetes Administrator(CKA) with Practice Tests 강의를 공부한 내용입니다.
Certified Kubernetes Administrator (CKA) with Practice Tests
<p><strong>CKA Certification Course – Certified Kubernetes Administrator</strong></p><p>Kubernetes is one of the highest trending technology in Cloud Computing as of today. Kubernetes had the fastest growth in job searches, over 173% from a year before,
www.udemy.com
Logging in Docker
Docker 컨테이너는 일반적으로 로그를 표준 출력(Standard Output, stdout) 으로 기록함
예를 들어, 웹 서버의 이벤트를 시뮬레이션하는 event-simulator 컨테이너를 실행하면 다음과 같은 로그가 출력됨
docker run kodekloud/event-simulator
2018-10-06 15:57:15,937 - root - INFO - USER1 logged in
2018-10-06 15:57:16,943 - root - INFO - USER2 logged out
2018-10-06 15:57:17,944 - root - INFO - USER3 is viewing page3
...
컨테이너를 백그라운드에서 실행하면 터미널에 로그가 표시되지 않음
docker run -d kodekloud/event-simulator
docker logs -f <container_id>
- 옵션 설명
옵션 설명 logs 컨테이너 로그 조회 -f 로그를 실시간(Follow)으로 출력
Logging in Kubernetes
동일한 이미지를 Kubernetes Pod로 실행
Pod 생성
apiVersion: v1
kind: Pod
metadata:
name: event-simulator-pod
spec:
containers:
- name: event-simulator
image: kodekloud/event-simulator
Pod 생성
kubectl create -f event-simulator.yaml
로그 조회
kubectl logs -f event-simulator-pod
2018-10-06 15:57:15,937 - root - INFO - USER1 logged in
2018-10-06 15:57:16,943 - root - INFO - USER2 logged out
2018-10-06 15:57:17,944 - root - INFO - USER2 is viewing page2
...
Logging with Multiple Containers in a Pod
Kubernetes는 하나의 Pod 안에 여러 컨테이너를 실행할 수 있음
예시:
apiVersion: v1
kind: Pod
metadata:
name: event-simulator-pod
spec:
containers:
- name: event-simulator
image: kodekloud/event-simulator
- name: image-processor
image: some-image-processor
로그 조회시 주의 사항
- 멀티 컨테이너 Pod에서 kubectl logs -f event-simulator-pod 를 실행 시 어떤 컨테이너의 로그를 보여줘야 하는지 알 수 없기에 오류 발생 가능
- 컨테이너 이름을 지정해줘야함
- kubectl logs -f event-simulator-pod event-simulator kubectl logs -f event-simulator-pod -c event-simulator
로그 확인 시 유용한 옵션
최근 로그 조회
kubectl logs event-simulator-pod
실시간 로그 조회
kubectl logs -f event-simulator-pod
이전 컨테이너 로그 확인 (컨테이너가 재시작된 경우)
kubectl logs --previous event-simulator-pod
로그 마지막 N줄만 보기
kubectl logs --tail=20 event-simulator-pod
특정 시간 이후 로그 보기 (최근 1시간 로그만 출력)
kubectl logs --since=1h event-simulator-pod
CKA 시험 관점 핵심 정리
로그 확인
Pod 로그 조회
kubectl logs pod-name
실시간 로그 조회
kubectl logs -f pod-name
멀티 컨테이너 Pod
컨테이너 지정 필수
kubectl logs pod-name -c container-name
이전 컨테이너 로그
CrashLoopBackOff 문제 분석 시 자주 사용
kubectl logs pod-name --previous
시험에서 자주 나오는 문제
특정 Pod 로그 확인
kubectl logs nginx-pod
특정 컨테이너 로그 확인
kubectl logs nginx-pod -c sidecar
실시간 모니터링
kubectl logs -f nginx-pod
CrashLoopBackOff 원인 확인
kubectl logs nginx-pod --previous
한 줄 요약
kubectl logs <pod>
kubectl logs -f <pod>
kubectl logs <pod> -c <container>
kubectl logs <pod> --previous
'Kubernetes' 카테고리의 다른 글
| [Kubernetes] Commands and Arguments in Docker (0) | 2026.10.04 |
|---|---|
| [Kubernetes] Rolling Updates and Rollbacks (0) | 2026.09.27 |
| [Kubernetes] Monitor Cluster Components (0) | 2026.09.21 |
| [Kubernetes] Admission Controllers (0) | 2026.09.19 |
| [Kubernetes] Configuring Scheduler Profiles (0) | 2026.09.09 |