CertGrid CertGrid
Troubleshooting·Certified Kubernetes Application Developer

Container Logs and --previous

When a container restarts, kubectl logs shows you the new one - which has not failed yet, so the error is not in it. --previous reads the dead container's log, and it is where the actual cause lives. This shows that gap directly, then the selector, prefix and timestamp flags that make logs usable across a whole Deployment.

Observability and Maintenance Guide 41 of 44 Beginner

--previous reads the log of the last terminated container, which the kubelet keeps only until that container is garbage-collected. A container that exits instantly and restarts in a tight loop may already have lost it - the failure reads unable to retrieve container logs for containerd://..., which was produced twice while capturing this guide.

A crashing Pod, a three-replica Deployment and a two-container Pod, all in one namespace.
Server NameIP AddressOSRolesCPURAMHDD
CKA1001192.168.0.175Ubuntu 26.04 LTSControl Plane Node2 Core4 GB50 GB
CKA1001-NODE01192.168.0.176Ubuntu 26.04 LTSWorker Node2 Core4 GB50 GB
CKA1001-NODE02192.168.0.177Ubuntu 26.04 LTSWorker Node2 Core4 GB50 GB
CKA1001-NODE03192.168.0.178Ubuntu 26.04 LTSWorker Node2 Core4 GB50 GB

This guide includes

Use this when a container restarted and the error is nowhere in the logs. This matters because kubectl logs shows you the container running now, which has not failed yet - the evidence is in the one that died.

Before you start

  1. The error that is not in the logs

  2. The flags worth knowing

  3. A multi-container Pod needs a name

  4. What you cannot get back

Official sources