CrashLoopBackOff: read the logs first

An API restarts forever after a copy-paste deploy. The logs say why; the fix is already in the namespace.

Beginner Break/fix Starts broken 15 min 100 points

Goal

The orders-api Deployment in namespace shop is stuck in CrashLoopBackOff. Find out why from the logs, and get both replicas Running using the database credentials that already exist in the namespace. Do not paste the connection string into the Deployment.

How it is graded

  • DATABASE_URL comes from Secret orders-db, key url30 pts
  • Both orders-api pods are Running and ready30 pts
  • Deployment reports 2 available replicas20 pts
  • ?3 hidden checks, revealed when you grade. They make sure the fix keeps to the rules in the goal.

Your cluster

  • 2 × worker 4 CPU · 16Gi

In production

  • kubectl logs --previous shows the output of the last crashed container, which is often where the real error is.
  • Restart back-off grows to 5 minutes, so after a fix watch kubectl rollout status instead of waiting on the old pods.
  • Many teams sync credentials from a secret manager (for example with External Secrets or the Secrets Store CSI Driver) instead of creating Secrets by hand.

Further reading

Written by @prianshu-git. View the source.