---
title: "kubectl logs --previous fails while a crashing pod shows Error instead of CrashLoopBackOff"
url: "https://www.dariuszparys.com/notes/kubectl-logs-previous-fails-while-pod-shows-error"
author: "Dariusz Parys"
published: 2026-11-20T00:00:00.000Z
description: "kubectl logs --previous fails while a crashing pod shows Error, because the finished instance is still the current container and a previous one exists only during CrashLoopBackOff."
tags:
  - "Kubernetes"
  - "Observability"
---

# kubectl logs --previous fails while a crashing pod shows Error instead of CrashLoopBackOff

## Context

A pod whose container keeps exiting with an error (here exit code 3, on Kubernetes v1.37 with containerd) doesn't sit in `CrashLoopBackOff` all the time. Its STATUS alternates between two states:

- `Error`: `state.terminated`, the instance that just finished
- `CrashLoopBackOff`: `state.waiting`, the kubelet in back-off before the next start

## Insight

`kubectl logs <pod> --previous` only works in the `CrashLoopBackOff` window. While the pod shows `Error`, the finished instance is still the _current_ container, so there is no previous one, and the command fails:

```
unable to retrieve container logs for containerd://…
```

Plain `kubectl logs <pod>` returns the crashed instance's output in both windows. So an error from `--previous` at seemingly random moments is a timing issue, not a missing log.

## In scripts

Check STATUS first, or just use plain `logs`:

```bash
status=$(kubectl get pod crasher -o jsonpath='{.status.containerStatuses[0].state.waiting.reason}')
if [ "$status" = "CrashLoopBackOff" ]; then
  kubectl logs crasher --previous
else
  kubectl logs crasher            # Error window: the finished instance is current
fi
kubectl get pod crasher -o jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}'
```
