Skip to main content

[12] Pod Log 추출

❓Record the extracted log lines

  • Monitor the logs of pod custom-app and: Extract log lines corresponding to error file not found. write them to /var/CKA2022/podlog
    • 작업 클러스터: hk8s

Reference

docs에서 reference 검색 > logs 검색

Kubectl Reference Docs

실습

[user@console ~]$ kubectl config use-context hk8s

[user@console ~]$ kubectl get pods custom-app

[user@console ~]$ kubectl logs custom-app | grep 'file not found'

[user@console ~]$ kubectl logs custom-app | grep 'file not found' > /var/CKA2022/podlog

# 잘 들어갔는지 확인
[user@console ~]$ cat /var/CKA2022/podlog

기출문제 (1번)

List pod logs named "frontend" and search for the pattern "started" and write it to a file "/opt/error-logs"

  • 답안

    kubectl get pod frontend
    
    kubectl logs frontend | grep -i "started" > /opt/error-logs
    
    # 확인
    cat /opt/error-logs
    

기출문제 (7번)

Monitor the logs of pod foo and: Extract log lines corresponding to error unable-to-access-website Write them to /opt/KULM00201/foo

  • 답안

    kubectl get pods
    --> foo라는 이름의 pod있는지 확인
    
    kubectl logs foo | grep unable-to-access-website
    
    kubectl logs foo | grep unable-to-access-website > /opt/KULM00201/foo
    

기출문제 (17번)

Task Monitor the logs of pod bar and:

  • Extract log lines corresponding to error file-not-found
  • Write them to /opt/KUTR00101/bar
  • 답안
    kubectl logs bar | grep file-not-found
    
    kubectl logs bar | grep file-not-found > /opt/KUTR00101/bar