Skip to main content
In this lesson we’ll learn how to inspect application logs in Kubernetes, interpret log output, and troubleshoot two common scenarios:
  • Identify a user issue from logs for a single-container Pod.
  • Handle Pods with multiple containers when viewing logs.

1) Inspect a single-container Pod and identify the issue

Steps to inspect logs for a Pod that contains a single container:
  1. Confirm the Pod is running:
  1. View the application logs for the Pod:
Example application log output (single-container Pod):
Analysis
  • Look for repeated WARNING entries. Here, multiple WARNINGs indicate USER5 repeatedly failed to log in.
  • The log message clearly states the reason: the account is locked due to many failed login attempts.
Conclusion
  • USER5 cannot access the application because their account is locked after too many failed login attempts.

2) Inspect logs for a multi-container Pod and identify the issue

When a Pod runs more than one container, you must specify which container’s logs you want to read. If you run the logs command without a container name:
You may see an error like this:
This indicates the Pod hosts multiple containers (for example, webapp and db). To read logs from the web application container, include -c with the container name:
Example logs from the webapp container:
Analysis
  • This webapp container log includes WARNING entries for two different user-related issues:
    • USER5: repeated failed logins because the account is locked.
    • USER30: order failure due to an item being out of stock.
  • The purchasing problem reported by users is represented by the USER30 warnings: the item is OUT OF STOCK.
Best practice: if you’re unsure which container to inspect, list containers for the Pod:
When a Pod has multiple containers, always use kubectl logs <pod> -c <container> to select which container’s logs you want to read.

Quick reference

Summary

  • Single-container Pod: Inspect logs with kubectl logs <pod-name>. From the sample logs, USER5 cannot access the app because their account is locked after too many failed login attempts.
  • Multi-container Pod: Specify the container with -c (for example, kubectl logs webapp2 -c webapp). From the webapp container logs, the purchase failures are caused by items being OUT OF STOCK (USER30).

Watch Video