Skip to content
Latchkey

kubectl wait: Command Reference for CI/CD

Block on a real condition instead of polling get in a loop.

kubectl wait blocks until objects meet a condition, then returns, exiting non-zero on timeout. It replaces brittle sleep-and-poll loops in CI. This reference covers the --for forms and a synchronization example.

Common flags and usage

  • --for=condition=Ready: wait until pods report Ready
  • --for=condition=Available: wait for a Deployment to be Available
  • --for=condition=complete: wait for a Job to finish
  • --for=delete: wait until an object is gone (teardown)
  • --for=jsonpath='{.status.phase}'=Running: wait on an arbitrary field
  • --timeout=120s: cap the wait and exit non-zero on expiry

Example

shell
# Wait for a migration Job, then for the app to be Available
kubectl wait --for=condition=complete job/migrate --timeout=300s
kubectl wait --for=condition=Available deploy/web --timeout=120s
kubectl wait --for=condition=Ready pod -l app=web --timeout=120s

In CI

Use wait before any step that assumes a resource is up: before port-forwarding, before running smoke tests, or before deleting a namespace (--for=delete). It exits non-zero on timeout, which fails the step cleanly instead of letting a later command hit a not-yet-ready resource.

Key takeaways

  • wait replaces sleep-and-poll loops with a real condition check.
  • --for supports condition=, delete, and jsonpath= forms.
  • It exits non-zero on timeout, so it gates steps cleanly.

Related guides

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