Kubectl wait: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(16 intermediate revisions by the same user not shown)
Line 5: Line 5:
=Overview=
=Overview=


The command waits for a specific [[Kubernetes_Pod_and_Container_Concepts#Pod_Conditions|condition]], as reported by the ".status.conditions" field on a pod state,  on one or many pods. If more than one pod is specified, the condition must be seen in every pod. Alternatively, the command can wait for a specific pod to be deleted.
The command waits for a specific [[Kubernetes_Pod_and_Container_Concepts#Pod_Conditions|condition]], as reported by the ".status.conditions" field on a pod state,  on one or many pods. If more than one pod is specified, the condition must be seen in every pod. Alternatively, the command can wait for a specific pod to be deleted. The command exits with 0 if the resource is found and the conditions are met, or with a non-zero status if the resource is not found, or the condition is not met. Unless a specific timeout is provided with [[#--timeout|--timeout]], the default timeout occurs in <font color=darkgray>?</font> seconds.


<font color=darkgray>The documentation mentions "resources" instead of pods. Can wait be applied for other things than pods? If yes, what is them meaning of "condition" in that context, as other resources may not have conditions?</font>
==Using kubectl wait with Other Resources then Pods==
 
The documentation mentions that wait applies to "resources", not specifically pods. Can wait be applied for other things than pods? If yes, what is them meaning of "condition" in that context, as other resources may not have conditions? This discussion thread shows that the matter is not settled, at least at the time of writing: https://github.com/kubernetes/kubernetes/issues/80828


=Wait for a Specific Condition=
=Wait for a Specific Condition=


kubectl wait --for=condition=Ready pod <''pod-name''>
==Wait on a Pod Specified by Name==
 
<syntaxhighlight lang='bash'>
kubectl wait --for=condition=Ready pod <pod-name>
</syntaxhighlight>
 
==Wait on a Pod Specified by Label==
 
<syntaxhighlight lang='bash'>
kubectl wait --for=condition=Ready -l color=blue
</syntaxhighlight>
 
For more details on selector syntax see [[#-l.2C_--selector|option -l, --selector]] below.


=Wait for Deletion=
=Wait for Deletion=


  kubectl wait --for=delete pod <''pod-name''> --timeout=60s
==Pod Deletion==
 
Pod specified by name:
 
<syntaxhighlight lang='bash'>
kubectl wait --for=delete pod <pod-name> --timeout=60s
</syntaxhighlight>
 
Pod specified by selector:
 
  kubectl wait --for=delete pod -l color=blue --timeout=60s
 
==Namespace Deletion==
 
<syntaxhighlight lang='bash'>
kubectl wait --for=delete namespace <namespace-name> --timeout=60s
</syntaxhighlight>


=Options=
=Options=
Line 23: Line 53:
The length of time to wait before giving up.  Zero means check once and don't wait, negative means wait for a week.
The length of time to wait before giving up.  Zero means check once and don't wait, negative means wait for a week.


{{Warn|The resource must '''exist''' for this option to be effective. If the resource does not exist, then the wait command exits immediately with an error message ("Error from server (NotFound): pods "..." not found"), irrespective of the timeout value.}}
{{Warn|🛑 The resource must '''exist''' for this option to be effective. If the resource is specified by name and does not exist, then the wait command exits immediately with an error message ("Error from server (NotFound): pods "..." not found"), irrespective of the timeout value. If the resource is specified by selector, the error message is "at least one resource must be specified to use a selector" or "no matching resources found". This is a known issue: https://github.com/kubernetes/kubernetes/issues/83242}}
 
--timeout=30s
 
 


<syntaxhighlight lang='bash'>
... --timeout=30s ...
</syntaxhighlight>


----------
==-l, --selector==
      --all=false: Select all resources in the namespace of the specified resource types
  -A, --all-namespaces=false: If present, list the requested object(s) across all namespaces. Namespace in current
context is ignored even if specified with --namespace.
      --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in
the template. Only applies to golang and jsonpath output formats.
      --field-selector='': Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector
key1=value1,key2=value2). The server only supports a limited number of field queries per type.
  -f, --filename=[]: identifying the resource.
      --for='': The condition to wait on: [delete|condition=condition-name].
  -o, --output='': Output format. One of:
json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
  -R, --recursive=true: Process the directory used in -f, --filename recursively. Useful when you want to manage related
manifests organized within the same directory.
  -l, --selector='': Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)
      --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The
template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].


Usage:
Specifies the selector (label query) to use to identify the resource. The expression supports '=', '==', and '!='.
  kubectl wait ([-f FILENAME] | resource.group/resource.name | resource.group [(-l label | --all)]) [--for=delete|--for
condition=available] [options]


Use "kubectl options" for a list of global command-line options (applies to all commands).
<syntaxhighlight lang='bash'>
Ovidiu-Feodorov:~ ovidiufeodorov$
-l key1=value1,key2!=value2
</syntaxhighlight>

Latest revision as of 18:53, 17 March 2021

Internal

Overview

The command waits for a specific condition, as reported by the ".status.conditions" field on a pod state, on one or many pods. If more than one pod is specified, the condition must be seen in every pod. Alternatively, the command can wait for a specific pod to be deleted. The command exits with 0 if the resource is found and the conditions are met, or with a non-zero status if the resource is not found, or the condition is not met. Unless a specific timeout is provided with --timeout, the default timeout occurs in ? seconds.

Using kubectl wait with Other Resources then Pods

The documentation mentions that wait applies to "resources", not specifically pods. Can wait be applied for other things than pods? If yes, what is them meaning of "condition" in that context, as other resources may not have conditions? This discussion thread shows that the matter is not settled, at least at the time of writing: https://github.com/kubernetes/kubernetes/issues/80828

Wait for a Specific Condition

Wait on a Pod Specified by Name

kubectl wait --for=condition=Ready pod <pod-name>

Wait on a Pod Specified by Label

kubectl wait --for=condition=Ready -l color=blue

For more details on selector syntax see option -l, --selector below.

Wait for Deletion

Pod Deletion

Pod specified by name:

kubectl wait --for=delete pod <pod-name> --timeout=60s

Pod specified by selector:

kubectl wait --for=delete pod -l color=blue --timeout=60s

Namespace Deletion

kubectl wait --for=delete namespace <namespace-name> --timeout=60s

Options

--timeout

The length of time to wait before giving up. Zero means check once and don't wait, negative means wait for a week.


🛑 The resource must exist for this option to be effective. If the resource is specified by name and does not exist, then the wait command exits immediately with an error message ("Error from server (NotFound): pods "..." not found"), irrespective of the timeout value. If the resource is specified by selector, the error message is "at least one resource must be specified to use a selector" or "no matching resources found". This is a known issue: https://github.com/kubernetes/kubernetes/issues/83242

... --timeout=30s ...

-l, --selector

Specifies the selector (label query) to use to identify the resource. The expression supports '=', '==', and '!='.

-l key1=value1,key2!=value2