kubectl-wait
Wait for Kubernetes resource condition to be met
TLDR
Wait for a deployment to become available
Wait for all pods with a certain [l]abel to be ready
Wait for a pod to be deleted
Wait for a job to complete, within 120 seconds (if the condition isn't met on time, the exit status will be unsuccessful)
SYNOPSIS
kubectl wait [TYPE[/NAME | NAME_PREFIX | /NAME | -l label_selector]] [--for=duration|time|delete|condition=string] [--timeout=duration]
PARAMETERS
--for=
Condition to wait for: duration (e.g., 5s, 1m), datetime (e.g., 2023-01-01T00:00:00Z), delete, or condition=string (e.g., Ready, Available). Default: 0
--timeout=
Max wait time before exit (e.g., 60s, 5m). Default: 30s
TYPE[/NAME | NAME_PREFIX | /NAME | -l label_selector]
Resource specifier: kind/name, prefix, exact name, labels, file (-f), or stdin
--field-selector=
Filter by field query (e.g., status.phase=Running). Supports '=', '==', '!='
--grace-period=
Wait time for deletion finalization before return. Default: -1 (no wait)
DESCRIPTION
kubectl wait is a Kubernetes CLI subcommand that blocks until specified resources satisfy defined conditions, ideal for scripting, automation, and CI/CD pipelines. It polls resources at intervals, checking statuses like pod readiness, deployment availability, or custom conditions.
Target resources by name (e.g., pod/mypod), type with label selectors (e.g., deployments -l app=myapp), filenames, or stdin. Common uses include waiting for pods to be Ready, jobs to complete, or resources to be deleted.
Specify conditions with --for: durations (e.g., 5m), datetimes, delete, or condition=string like condition=Available. Timeouts prevent hangs, defaulting to 30s. Exit codes: 0 on success, 1 on timeout/failure.
This command simplifies orchestration by ensuring prerequisites before proceeding, reducing race conditions in deployments.
CAVEATS
Polls resources periodically (not real-time); may miss short-lived states. Timeouts are strict. Does not support all resource conditions—check docs for compatibility. High usage in loops can overload API server.
EXAMPLES
kubectl wait --for=condition=Ready pod/mypod
kubectl wait --for=condition=Available deployment/myapp --timeout=300s
kubectl wait --for=delete pod/mypod
kubectl wait --for=condition=complete job/myjob -l app=batch
EXIT CODES
0: Condition met
1: Timeout, error, or condition unmet
HISTORY
Introduced in Kubernetes v1.12 (2018); enhanced in v1.18+ with broader condition support and --for=delete. Evolved alongside kubectl for better automation.
SEE ALSO
kubectl-get(1), kubectl-describe(1), kubectl-rollout(1), watch(1)


