kubectl wait for pod readiness¶
kubectl wait for pod readiness refers to the use of the kubectl wait command to block the command line session until one or more [[Pods]] reach a specific condition, such as ready.^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md]
This is typically used in automation scripts or deployment workflows to ensure that a service has fully started before proceeding with subsequent steps, such as running integration tests or configuring Ingress rules.
Syntax¶
The general syntax for waiting on a pod to become ready involves specifying the target resource type, the desired condition, and a timeout duration^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md]:
[kubectl](<./kubectl.md>) wait --namespace <namespace> \
--for=condition=ready pod \
--selector=<label-selector> \
--timeout=<duration>
Key Parameters¶
--for=condition=ready: Specifies that the command should wait until thestatus.conditionof the pod isReady.^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md]--selector: Filters the pods to wait for based on label selectors (e.g.,app.kubernetes.io/component=controller).^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md]--timeout: Defines the maximum time to wait before the command fails and exits. If the condition is not met within this time, the command will return a non-zero exit code.^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md]
Examples¶
Waiting for Ingress Controller¶
When deploying an Ingress controller like NGINX, it is common practice to wait until the controller pods are ready before creating Ingress resources^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md].
[kubectl](<./kubectl.md>) wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=120s
In this example, the command pauses execution until a pod with the label app.kubernetes.io/component=controller in the ingress-nginx namespace reports as Ready, or until 120 seconds have passed^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md].
Related Concepts¶
Sources¶
^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md]