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:- Confirm the Pod is running:
- Inspect the Pod logs:
- 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:
webapp-2 has two containers, specify which container’s logs you want. To view the web application logs, pass the container name with -c:
- 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
-cto 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 USER5orkubectl logs <pod> | grep "USER30").
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}'.