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=120sIn 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
kubectl Cheat Sheet: Commands for Everyday KubernetesA kubectl cheat sheet - get, describe, logs, apply, rollout, debug, and context commands for daily Kubernetes…
kubectl rollout status: Command Reference for CI/CDReference for kubectl rollout status: block until a rollout completes and exit non-zero on failure, the canon…
kubectl get: Command Reference for CI/CDReference for kubectl get: list resources, output formats, label and field selectors, jsonpath extraction, an…
kubectl port-forward: Command Reference for CI/CDReference for kubectl port-forward: tunnel a local port to a pod or service for CI smoke tests, the readiness…