Use kubectl to wait for Jobs to succeed

No need to poll: there's a subcommand for that.
pull/37596/head
Tim Bannister 2022-10-29 19:49:51 +01:00
parent c6ec678fe7
commit 5ed062fb1f
No known key found for this signature in database
GPG Key ID: 1E76582C4F66FA48
3 changed files with 27 additions and 3 deletions

View File

@ -244,7 +244,13 @@ So, now run the Job:
kubectl apply -f ./job.yaml kubectl apply -f ./job.yaml
``` ```
Now wait a bit, then check on the job. You can wait for the Job to succeed, with a timeout:
```shell
# The check for condition name is case insensitive
kubectl wait --for=condition=complete --timeout=300s job/job-wq-1
```
Next, check on the Job:
```shell ```shell
kubectl describe jobs/job-wq-1 kubectl describe jobs/job-wq-1
@ -285,7 +291,9 @@ Events:
14s 14s 1 {job } Normal SuccessfulCreate Created pod: job-wq-1-p17e0 14s 14s 1 {job } Normal SuccessfulCreate Created pod: job-wq-1-p17e0
``` ```
All our pods succeeded. Yay.
All the pods for that Job succeeded. Yay.

View File

@ -208,9 +208,18 @@ Events:
FirstSeen LastSeen Count From SubobjectPath Type Reason Message FirstSeen LastSeen Count From SubobjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ ------- --------- -------- ----- ---- ------------- -------- ------ -------
33s 33s 1 {job-controller } Normal SuccessfulCreate Created pod: job-wq-2-lglf8 33s 33s 1 {job-controller } Normal SuccessfulCreate Created pod: job-wq-2-lglf8
```
You can wait for the Job to succeed, with a timeout:
```shell
# The check for condition name is case insensitive
kubectl wait --for=condition=complete --timeout=300s job/job-wq-2
```
```shell
kubectl logs pods/job-wq-2-7r7b2 kubectl logs pods/job-wq-2-7r7b2
```
```
Worker with sessionID: bbd72d0a-9e5c-4dd6-abf6-416cc267991f Worker with sessionID: bbd72d0a-9e5c-4dd6-abf6-416cc267991f
Initial queue state: empty=False Initial queue state: empty=False
Working on banana Working on banana

View File

@ -107,7 +107,14 @@ When you create this Job, the control plane creates a series of Pods, one for ea
Because `.spec.parallelism` is less than `.spec.completions`, the control plane waits for some of the first Pods to complete before starting more of them. Because `.spec.parallelism` is less than `.spec.completions`, the control plane waits for some of the first Pods to complete before starting more of them.
Once you have created the Job, wait a moment then check on progress: You can wait for the Job to succeed, with a timeout:
```shell
# The check for condition name is case insensitive
kubectl wait --for=condition=complete --timeout=300s job/indexed-job
```
Now, describe the Job and check that it was successful.
```shell ```shell
kubectl describe jobs/indexed-job kubectl describe jobs/indexed-job