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
- Kubernetes1.36.4
- Runtimecontainerd 2.2.6
- CNICalico v3.32.1
- TimeAbout 14 min
- Reviewed23 August 2026
Written against the versions above. `--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.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| CKA1001 | 192.168.0.175 | Ubuntu 26.04 LTS | Control Plane Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE01 | 192.168.0.176 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE02 | 192.168.0.177 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE03 | 192.168.0.178 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
Before you start
- A cluster and kubectl.
- The session creates namespace
ckad-logs, a Pod that runs for 25 seconds and then exits 3, a Deployment with three replicas, and a two-container Pod.
-
The error that is not in the logs
-
The flags worth knowing
-
A multi-container Pod needs a name
-
What you cannot get back