logs
What is logs?
logs: Print a container's stdout/stderr. Add -f to follow, --previous to see the crashed container's logs. kubectl logs shows what a container wrote to its standard output and error streams. kubectl logs web-7d9f8c prints the logs of that pod, and -f keeps following new lines as they arrive. --previous is the option people miss most. When a container crashes and restarts, the logs of the crashed instance explain why, and --previous shows exactly those.
Frequently asked questions about logs
What should you keep in mind with logs?
For a pod with several containers, choose one with -c. kubectl logs deploy/web picks a pod from a Deployment for you, and -l app=web shows logs from all matching pods. Kubernetes keeps only recent logs and loses them when a pod is deleted, so for anything you may need later, ship logs to a central system such as Loki or another logging service.
What does an example of logs look like?
kubectl logs -f web-7d9f8c-abc12 kubectl logs web-7d9f8c-abc12 --previous At a glance
| Category | Kubernetes |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |