← 返回命令列表

Linux command

kubectl-wait 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Wait for pod ready

kubectl wait --for=condition=Ready pod/[pod-name]

Wait for deletion

kubectl wait --for=delete pod/[pod-name]

Wait for creation

kubectl wait --for=create secret/[name]

Wait with timeout

kubectl wait --for=condition=Ready pod/[pod-name] --timeout=[60s]

Wait for deployment available

kubectl wait --for=condition=Available deployment/[name]

Wait with label selector across resources

kubectl wait --for=condition=Ready pods -l [app=myapp]

Wait for a JSONPath value

kubectl wait --for=jsonpath='{.status.phase}'=Running pod/[name]

Wait across all namespaces

kubectl wait --for=condition=Ready pods --all -A

说明

kubectl wait blocks execution until one or more Kubernetes resources reach a specified condition, making it an essential synchronization primitive for shell scripts, CI/CD pipelines, and automation workflows. Rather than polling with repeated `kubectl get` calls, it efficiently watches the resource and returns as soon as the condition is satisfied or the timeout expires. The command supports built-in condition checks such as `condition=Ready` and `condition=Available`, resource deletion events via `--for=delete`, and arbitrary field matching through JSONPath expressions like `jsonpath='{.status.phase}'=Running`. It can target individual resources by name or groups of resources matched by label selectors, and always defaults to a 30-second timeout unless overridden with --timeout.

参数

--for _EXPR_
Condition to wait on. Accepts `create`, `delete`, `condition=<name>=<value>`, or `jsonpath='{...}'=<value>`. Default condition value is `true`.
--timeout _DURATION_
Maximum time to wait (e.g. 30s, 5m). Default is 30s. Zero means check once; a negative value waits up to a week.
--all
Select all resources of the given type in the namespace.
-A, --all-namespaces
Operate across all namespaces.
-l, --selector _QUERY_
Label selector to filter resources.
--field-selector _QUERY_
Field selector to filter resources.
-f, --filename _FILE_
Identify the resource(s) via a manifest file or directory.
-n, --namespace _NS_
Target namespace.
-o, --output _FORMAT_
Output format (json, yaml, name, go-template, jsonpath, ...).
--help
Display help information.

FAQ

What is the kubectl-wait command used for?

kubectl wait blocks execution until one or more Kubernetes resources reach a specified condition, making it an essential synchronization primitive for shell scripts, CI/CD pipelines, and automation workflows. Rather than polling with repeated `kubectl get` calls, it efficiently watches the resource and returns as soon as the condition is satisfied or the timeout expires. The command supports built-in condition checks such as `condition=Ready` and `condition=Available`, resource deletion events via `--for=delete`, and arbitrary field matching through JSONPath expressions like `jsonpath='{.status.phase}'=Running`. It can target individual resources by name or groups of resources matched by label selectors, and always defaults to a 30-second timeout unless overridden with --timeout.

How do I run a basic kubectl-wait example?

Run `kubectl wait --for=condition=Ready pod/[pod-name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --for _EXPR_ do in kubectl-wait?

Condition to wait on. Accepts `create`, `delete`, `condition=<name>=<value>`, or `jsonpath='{...}'=<value>`. Default condition value is `true`.