Net Eng

[CKA] - Pod Log 추출 본문

Cloud/Kubernetes

[CKA] - Pod Log 추출

欲心 2024. 1. 21. 10:48

[선수 지식]

kubectl logs POD
kubectl logs POD -c CONTAINER

 


 

[선수 작업]

kubectl config set-context hk8s --user=kubernetes-admin --cluster=kubernetes
mkdir -p /var/CKA2023
kubectl apply -f - <<EOF
kind: Pod
apiVersion: v1
metadata:
  name: custom-app
spec:
  containers:
  - name: custom-container
    image: busybox
    command:
    - '/bin/sh'
    - '-c'
    - >
      while true; 
      do 
        [ ! -f /filenotfound.txt ] && echo "[ ERROR ] file not found";
        sleep 10; 
      done
EOF

 


 

[문제]

작업 클러스터: hk8s

Monitor the logs of pod custom-app and: Extrat log lines corresponding to error file not found. Write them to /var/CKA2023/podlog.

 


 

[풀이]

kubectl config use-context hk8s

* hk8s 클러스터 사용

 

kubectl get pods custom-app

* Pod 확인

 

kubectl logs custom-app | grep 'file not found'

* file not found가 포함된 log 확인

 

kubectl logs custom-app | grep 'file not found' > /var/CKA2023/podlog

* 해당 로그를 파일에 기록

 

기록된 로그 확인


 

[참고]

 

명령줄 도구 (kubectl)

운영 수준의 컨테이너 오케스트레이션

kubernetes.io

'Cloud > Kubernetes' 카테고리의 다른 글

[CKA] - Init Container를 포함한 Pod 운영  (1) 2024.01.22
[CKA] - CPU 사용량이 높은 파드 검색  (1) 2024.01.21
[CKA] - Deployment & Expose the Service  (0) 2024.01.21
[CKA] - Node 정보 수집  (0) 2024.01.21
[CKA] - Node 관리  (0) 2024.01.21