Last week, I was troubleshooting an OpenSearch pod that kept restarting due to heap memory issues. I wanted to catch the crash trace, so I ran oc logs -p to pull the previous container's standard output.
A junior engineer watching my screen asked a simple question: How does OpenShift actually know where the previous logs are?
I knew the flag worked, but I had never dug into the exact mechanics. As I document across my blogs, the answer is always on the physical disk.
The Same Pod vs. A New Pod
First, you have to separate a pod restart from a pod replacement.
If a pod is evicted or replaced onto another node, the logs are completely gone. But when a container hits an OutOfMemory (OOM) error and crashes (a common outcome when cgroups v2 memory limits are crossed or working set memory spikes past pod requests), the pod itself does not die. The pod ID stays the same. The kubelet simply starts a new container process inside that existing pod.
When you run oc logs <pod>, it only shows you the standard output of the brand-new, active container. To see the crash, you append --previous (or -p).
The Worker Node Filesystem
OpenShift does not store container logs in etcd or memory. When your application writes to stdout or stderr, the container runtime intercepts that stream and writes it to a physical file on the worker node.
If you debug into the node and navigate to /var/log/pods/, you will see a directory mapped by namespace, pod name, and pod UID, with a subdirectory per container:
[root@worker ~]# ls -l /var/log/pods/total 4drwxr-xr-x. 3 root root 4096 Sep 30 09:20 myproject_opensearch-38546b76c-g2fbd_2cf0f8b0-7c7b-4b86-8a2d-30c86ad5743eInside the container's directory, logs are named after the container's restart count (<restart-count>.log):
[root@worker ~]# ls -l /var/log/pods/myproject_opensearch-38546b76c-g2fbd_2cf0f8b0-7c7b-4b86-8a2d-30c86ad5743e/opensearch/total 1232-rw-r--r--. 1 root root 552415 Sep 30 09:11 0.log-rw-r--r--. 1 root root 635497 Sep 30 09:21 1.log-rw-------. 1 root root 270528 Sep 30 09:11 0.log.20260930-180512.gzThe Lifecycle of the Logs
The kubelet passes the log path to CRI-O based on the container's restart count, and CRI-O writes directly to that file. Nothing gets renamed when a container crashes. Here is the actual sequence:
- First Run (0.log): When the container starts for the first time (restart count
0), the kubelet sets its log path to0.logand CRI-O streams stdout and stderr there. - Crash & New Container (1.log): When that container crashes, CRI-O closes
0.logand leaves it untouched on disk. As soon as the kubelet starts the replacement container (restart count1), it assigns the new container1.log. - Retention & Size Rotation: Previous restart logs (0.log, 1.log) stay on disk until the kubelet's log rotation (
containerLogMaxSizeandcontainerLogMaxFiles) rotates and compresses older files (such as0.log.20260930-180512.gz) or garbage-collects dead containers.
The CLI Call
When you run oc logs <pod> --previous, you are not querying the container directly. The OpenShift CLI sends an HTTP request to the API server, which forwards it to the /containerLogs endpoint on that specific node's kubelet.
The --previous flag instructs the kubelet to look at the pod's status, find the terminated container ID, and read the older 0.log file directly from the /var/log/pods/ directory instead of the active 1.log. The kubelet simply streams the contents of that dead file back through the API server to your terminal.
The /var/log/pods/ filesystem is completely ephemeral.
If the worker node restarts, or if the pod gets evicted to a different node, the log file is permanently gone. And also, if your pod crash-loops rapidly, the kubelet's garbage collector will delete 0.log to make room for 2.log.
Use --previous for immediate CLI triage, but ship your logs off the node if you want them to survive the night.
If you want to inspect previous container logs and pod events faster without repeating CLI flags, you can stream them directly in K9s. When a pod is not crashing at all but still failing traffic checks, see Pod Is Running but Not Ready, or if a container refuses to terminate after a crash on the node, check how uninterruptible sleep (D-state) processes get stuck in the kernel.