Skip to main content
In this lab we walk through inspecting application logs for deployed Pods using kubectl. You will learn how to view logs for single-container Pods, handle Pods with multiple containers, and identify root causes for user-reported problems by reading log output.

What you’ll do

  • Confirm Pods are running.
  • View application logs using kubectl logs.
  • Interpret log output to find the cause of reported issues.
  • Handle multi-container Pods by specifying the container name.

Scenario 1 — Inspect a single-container Pod

Steps:
  1. Confirm the Pod is running:
  2. Inspect the Pod logs:
Example application log output:
Analysis and conclusion:
  • The repeated WARNING entries for USER5 show repeated failed login attempts followed by an account lock.
  • Root cause of the access problem reported by user5: the account is locked due to too many failed login attempts. Remediate by unlocking the account or resetting the user’s credentials.

Scenario 2 — Pod with multiple containers (web app + DB)

When a Pod runs multiple containers (for example a web application container and a database container), kubectl logs <pod-name> requires a container name. If you omit the container name you’ll see an error. Example commands and output:
Because webapp-2 has two containers, specify which container’s logs you want. To view the web application logs, pass the container name with -c:
Example web app log output (customer purchase scenario):
Analysis and conclusion:
  • The web app logs show two separate warning patterns:
    • USER5 repeatedly failing to log in because the account is locked.
    • USER30 orders failing due to items being out of stock.
  • If the user-reported problem is about making a purchase, the relevant root cause is USER30’s orders failing because the item is out of stock.

Quick reference — common kubectl logs commands


Summary and best practices

  • Always confirm Pod status (kubectl get pods) before inspecting logs.
  • For multi-container Pods, specify the container name with -c to avoid ambiguous logs.
  • Scan logs for repeated WARNING/ERROR entries and timestamps to correlate events with reported incidents.
  • When troubleshooting user reports, filter logs for user identifiers or keywords (for example, grep USER5 or kubectl logs <pod> | grep "USER30").
Resources:
If a Pod has multiple containers, use kubectl logs <pod-name> -c <container-name> to select which container’s logs to display. You can discover container names with kubectl describe pod <pod-name> or kubectl get pod <pod-name> -o jsonpath='{.spec.containers[*].name}'.

Watch Video