kubernetes/logs-pod

View Pod Logs

Fetch logs from a specific pod.

pods
logs

Command

kubectl logs <pod-name>

Explanation

Displays standard output (stdout) and error (stderr) logs from containers in a pod. It’s commonly used for diagnosing runtime errors or crashes. Use '-f' to stream logs live, and '-c' when a pod has multiple containers. For previous runs, use '--previous' to fetch logs from terminated containers.

Common Use Cases

  • Debug runtime application errors
  • Monitor real-time container logs
  • Retrieve logs from previously crashed containers

Best Practices

  • Use '--timestamps' for chronological analysis
  • Combine with 'kubectl get pods' to quickly locate crashing pods

Common Mistakes to Avoid

  • Forgetting '-c' for multi-container pods
  • Expecting logs from pods that have already been deleted

Troubleshooting

Problem: No logs returned

Solution: Ensure the pod and container exist and check if logs are being written to stdout/stderr.

Examples

Show logs for the specified pod

kubectl logs my-app-pod-1234

View logs from a specific container

kubectl logs my-app-pod-1234 -c container1