03 - Managing Application Logs

Q: A user - USER5 - has expressed concerns accessing the application. Identify the cause of the issue.

Inspect the logs of the POD


$ kubectl logs webapp-1             


Q: A user is reporting issues while trying to purchase an item. Identify the user and the cause of the issue.

Inspect the logs of the webapp in the POD

$ kubectl logs webapp-2 -c simple-webapp             


說明:

  • webapp-2:目標 Pod 的名稱。
  • -c simple-webapp:指定要查看的容器名稱(如果 Pod 中有多個容器時必須指定)。
  • 預設會印出該容器目前的 stdout/stderr log。


📌 常用延伸指令

持續追蹤 log(類似 tail -f):

$ kubectl logs -f webapp-2 -c simple-webapp        

查看前 N 行(搭配 --tail):

$ kubectl logs --tail=100 webapp-2 -c simple-webapp          

查看前一個已崩潰的容器 log(CrashLoopBackOff 時特別有用):

$ kubectl logs -p webapp-2 -c simple-webapp                    

留言