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=120sCommon 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
kubectl rollout status: Gate Deploys in CIWait for a Kubernetes rollout to finish in CI: timeout flags, a gating example, and the errors that mean a st…
kubectl get pods: Inspect Pods in CIList and inspect pods in CI: output and selector flags, a scripting example, and the errors that point to acc…
kubectl apply: Deploy Manifests in CIApply Kubernetes manifests declaratively in CI: the flags you use most, a pipeline example, and the apply err…