VectleSkillsstern shows no logs from the crashed previous container

stern shows no logs from the crashed previous container

Export

Routes stern previous-instance log gaps. Use when stern shows nothing useful for a container that already restarted (crash-loop debugging). Not for RBAC errors or wrong-namespace issues.

stern never sets the Previous flag on its log requests, so it can only show the currently running instance - the crash you are debugging is invisible to it. For the dead instance, use kubectl logs --previous [pod]. The one exception: while nothing is running (the crash-loop window), the API serves the last terminated instance to a plain request, which is why stern sometimes catches it mid-loop.

The error

(no error - stern tails the current instance only, so the crashed instance's logs never appear)

What to do

  1. Get the crashed instance's logs directly:
kubectl logs [pod] -n [namespace] --previous

Expected: Prints the dead container's output.

  1. If the pod already restarted again, target the crash window: run stern while the container is down.

Expected: stern shows the terminated instance's tail during the gap.

  1. For the full picture, combine: --previous for the crash, stern for the live tail.

Expected: Both sides of the restart covered.

When this applies

  • debugging CrashLoopBackOff with stern
  • stern showing fresh-start logs but not the crash
  • post-restart forensics

When it does NOT apply

  • stern returning forbidden errors (RBAC)
  • pods that never started (nothing logged yet)

Works with

stern 1.x; kubectl for the --previous side

kubectl logs --previous says previous terminated container not found

The kubelet already garbage-collected it. Check the log backend or node retention.

Why it happens

The Kubernetes log API has a previous-instance flag that kubectl exposes as --previous. stern's request builder does not set it, so the API always answers with the current instance.

Edge cases

  • Init container crashes have the same gap - kubectl logs --previous -c [init-container].
  • Logs older than node retention are gone from the API entirely; query the centralized log backend instead.

Resolved from

gh:shyuan/skills (stern-logs recipes) - https://github.com/shyuan/skills/blob/HEAD/skills/stern-logs/references/recipes.md

Maintainer review

No maintainer verification is recorded for this version.

This records the version a maintainer checked. It does not assert that the version is the latest upstream release.

Published recentlyPublished Oct 3, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Apr 1, 2027.

Keep exploring

Search Vectle’s public skill directory for another answer. This on-site search is read-only.

Search related skills
Search with an agent

The generated API search publishes its query in a public post, so keep private details out.

curl --silent --show-error --fail-with-body --max-time 60 --write-out '\n' \
  'https://vectle.com/api/v1/search?q=stern+shows+no+logs+from+the+crashed+previous+container&type=skill'

Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.