Skip to content
Latchkey

kubectl wait: Block on Conditions in CI

Block until resources meet a condition (Ready, Complete, deleted) or a timeout fires.

kubectl wait pauses until a resource reaches a condition, which makes pipelines deterministic instead of sprinkling sleeps. Common uses are waiting for pods to be Ready, a Job to Complete, or a resource to be fully deleted.

Common flags

  • --for=condition=Ready - wait for a status condition
  • --for=delete - wait until the resource is removed
  • --timeout=DURATION - fail after this long, e.g. 120s
  • -l key=value / --all - select resources to wait on

Example in CI

Wait for all api pods to become Ready before testing.

shell
kubectl wait --for=condition=Ready pod \
  -l app=api -n prod --timeout=120s

Common errors in CI

  • error: timed out waiting for the condition - pods never became Ready in the window
  • error: no matching resources found - selector matched nothing (resource not created yet)
  • condition not met for ... - wrong --for condition for that resource type

Key takeaways

  • Blocks on a condition so pipelines avoid brittle sleeps.
  • Always set --timeout so a never-Ready resource fails the job.
  • no matching resources found means you waited before the resource existed.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →