Wait for kubernetes job to complete on either failure/success using command line Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Sidecar containers in Kubernetes Jobs?Wait for job/pod completion in Kubernetes or Google Container EngineWhat is stored in a kubernetes job and how do I check resource use of old job(s)?Kubernetes - Tell when Job is Completekubernetes jobs init containerList of Kubernetes status conditions for jobs?Have kube jobs start on waiting podsKubernetes Job Status checkHow to find out if a K8s job failed or succeeded using kubectl?Is there a better way to wait for Kubernetes job completion?

2 sample t test for sample sizes - 30,000 and 150,000

Etymology of 見舞い

How is an IPA symbol that lacks a name (e.g. ɲ) called?

Is there a verb for listening stealthily?

Is Bran literally the world's memory?

Why is one lightbulb in a string illuminated?

Like totally amazing interchangeable sister outfit accessory swapping or whatever

Unix AIX passing variable and arguments to expect and spawn

How to make an animal which can only breed for a certain number of generations?

Converting a text document with special format to Pandas DataFrame

lm and glm function in R

Can a Wizard take the Magic Initiate feat and select spells from the Wizard list?

Why these surprising proportionalities of integrals involving odd zeta values?

What's the difference between using dependency injection with a container and using a service locator?

/bin/ls sorts differently than just ls

Should man-made satellites feature an intelligent inverted "cow catcher"?

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?

How to leave only the following strings?

Why did Europeans not widely domesticate foxes?

Can 'non' with gerundive mean both lack of obligation and negative obligation?

Why does BitLocker not use RSA?

Can I take recommendation from someone I met at a conference?

Who's this lady in the war room?

Can a Knight grant Knighthood to another?



Wait for kubernetes job to complete on either failure/success using command line



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Sidecar containers in Kubernetes Jobs?Wait for job/pod completion in Kubernetes or Google Container EngineWhat is stored in a kubernetes job and how do I check resource use of old job(s)?Kubernetes - Tell when Job is Completekubernetes jobs init containerList of Kubernetes status conditions for jobs?Have kube jobs start on waiting podsKubernetes Job Status checkHow to find out if a K8s job failed or succeeded using kubectl?Is there a better way to wait for Kubernetes job completion?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








3















What is the best way to wait for kubernetes job to be complete? I noticed a lot of suggestions to use:



kubectl wait --for=condition=complete job/myjob


but i think that only works if the job is successful. if it fails, i have to do something like:



kubectl wait --for=condition=failure job/myjob


is there a way to wait for both conditions using wait? if not, what is the best way to wait for a job to either succeed or fail?










share|improve this question






























    3















    What is the best way to wait for kubernetes job to be complete? I noticed a lot of suggestions to use:



    kubectl wait --for=condition=complete job/myjob


    but i think that only works if the job is successful. if it fails, i have to do something like:



    kubectl wait --for=condition=failure job/myjob


    is there a way to wait for both conditions using wait? if not, what is the best way to wait for a job to either succeed or fail?










    share|improve this question


























      3












      3








      3


      2






      What is the best way to wait for kubernetes job to be complete? I noticed a lot of suggestions to use:



      kubectl wait --for=condition=complete job/myjob


      but i think that only works if the job is successful. if it fails, i have to do something like:



      kubectl wait --for=condition=failure job/myjob


      is there a way to wait for both conditions using wait? if not, what is the best way to wait for a job to either succeed or fail?










      share|improve this question
















      What is the best way to wait for kubernetes job to be complete? I noticed a lot of suggestions to use:



      kubectl wait --for=condition=complete job/myjob


      but i think that only works if the job is successful. if it fails, i have to do something like:



      kubectl wait --for=condition=failure job/myjob


      is there a way to wait for both conditions using wait? if not, what is the best way to wait for a job to either succeed or fail?







      kubernetes wait jobs kubectl kubernetes-jobs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 9 at 18:34









      Daein Park

      1,389410




      1,389410










      asked Mar 9 at 2:31









      ruazn2ruazn2

      224




      224






















          1 Answer
          1






          active

          oldest

          votes


















          1














          kubectl wait --for=condition=<condition name is waiting for a specific condition, so afaik it can not specify multiple conditions at the moment.



          My workaround is using oc get --wait, --wait is closed the command if the target resource is updated. I will monitor status section of the job using oc get --wait until status is updated. Update of status section is meaning the Job is complete with some status conditions.



          If the job complete successfully, then status.conditions.type is updated immediately as Complete. But if the job is failed then the job pod will be restarted automatically regardless restartPolicy is OnFailure or Never. But we can deem the job is Failed status if not to updated as Complete after first update.



          Look the my test evidence as follows.



          • Job yaml for testing successful complete


          # vim job.yml
          apiVersion: batch/v1
          kind: Job
          metadata:
          name: pi
          spec:
          parallelism: 1
          completions: 1
          template:
          metadata:
          name: pi
          spec:
          containers:
          - name: pi
          image: perl
          command: ["perl", "-wle", "exit 0"]
          restartPolicy: Never


          • It will show you Complete if it complete the job successfully.


          # oc create -f job.yml &&
          oc get job/pi -o=jsonpath='.status' -w &&
          oc get job/pi -o=jsonpath='.status.conditions[*].type' | grep -i -E 'failed|complete' || echo "Failed"

          job.batch/pi created
          map[startTime:2019-03-09T12:30:16Z active:1]Complete


          • Job yaml for testing failed complete


          # vim job.yml
          apiVersion: batch/v1
          kind: Job
          metadata:
          name: pi
          spec:
          parallelism: 1
          completions: 1
          template:
          metadata:
          name: pi
          spec:
          containers:
          - name: pi
          image: perl
          command: ["perl", "-wle", "exit 1"]
          restartPolicy: Never


          • It will show you Failed if the first job update is not Complete. Test if after delete the existing job resource.


          # oc delete job pi
          job.batch "pi" deleted

          # oc create -f job.yml &&
          oc get job/pi -o=jsonpath='.status' -w &&
          oc get job/pi -o=jsonpath='.status.conditions[*].type' | grep -i -E 'failed|complete' || echo "Failed"

          job.batch/pi created
          map[active:1 startTime:2019-03-09T12:31:05Z]Failed


          I hope it help you. :)






          share|improve this answer























          • i ended up just making a simple script to check the status as you had shown: until [[ $SECONDS -gt $end ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Failed")].status') == "True" ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Complete")].status') == "True" ]]; do

            – ruazn2
            Mar 15 at 23:52












          • That's great, and I'm sorry for showing the openshift cli example. But you can catch up as kubernetes cli, it's great !

            – Daein Park
            Mar 16 at 13:35











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073453%2fwait-for-kubernetes-job-to-complete-on-either-failure-success-using-command-line%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          kubectl wait --for=condition=<condition name is waiting for a specific condition, so afaik it can not specify multiple conditions at the moment.



          My workaround is using oc get --wait, --wait is closed the command if the target resource is updated. I will monitor status section of the job using oc get --wait until status is updated. Update of status section is meaning the Job is complete with some status conditions.



          If the job complete successfully, then status.conditions.type is updated immediately as Complete. But if the job is failed then the job pod will be restarted automatically regardless restartPolicy is OnFailure or Never. But we can deem the job is Failed status if not to updated as Complete after first update.



          Look the my test evidence as follows.



          • Job yaml for testing successful complete


          # vim job.yml
          apiVersion: batch/v1
          kind: Job
          metadata:
          name: pi
          spec:
          parallelism: 1
          completions: 1
          template:
          metadata:
          name: pi
          spec:
          containers:
          - name: pi
          image: perl
          command: ["perl", "-wle", "exit 0"]
          restartPolicy: Never


          • It will show you Complete if it complete the job successfully.


          # oc create -f job.yml &&
          oc get job/pi -o=jsonpath='.status' -w &&
          oc get job/pi -o=jsonpath='.status.conditions[*].type' | grep -i -E 'failed|complete' || echo "Failed"

          job.batch/pi created
          map[startTime:2019-03-09T12:30:16Z active:1]Complete


          • Job yaml for testing failed complete


          # vim job.yml
          apiVersion: batch/v1
          kind: Job
          metadata:
          name: pi
          spec:
          parallelism: 1
          completions: 1
          template:
          metadata:
          name: pi
          spec:
          containers:
          - name: pi
          image: perl
          command: ["perl", "-wle", "exit 1"]
          restartPolicy: Never


          • It will show you Failed if the first job update is not Complete. Test if after delete the existing job resource.


          # oc delete job pi
          job.batch "pi" deleted

          # oc create -f job.yml &&
          oc get job/pi -o=jsonpath='.status' -w &&
          oc get job/pi -o=jsonpath='.status.conditions[*].type' | grep -i -E 'failed|complete' || echo "Failed"

          job.batch/pi created
          map[active:1 startTime:2019-03-09T12:31:05Z]Failed


          I hope it help you. :)






          share|improve this answer























          • i ended up just making a simple script to check the status as you had shown: until [[ $SECONDS -gt $end ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Failed")].status') == "True" ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Complete")].status') == "True" ]]; do

            – ruazn2
            Mar 15 at 23:52












          • That's great, and I'm sorry for showing the openshift cli example. But you can catch up as kubernetes cli, it's great !

            – Daein Park
            Mar 16 at 13:35















          1














          kubectl wait --for=condition=<condition name is waiting for a specific condition, so afaik it can not specify multiple conditions at the moment.



          My workaround is using oc get --wait, --wait is closed the command if the target resource is updated. I will monitor status section of the job using oc get --wait until status is updated. Update of status section is meaning the Job is complete with some status conditions.



          If the job complete successfully, then status.conditions.type is updated immediately as Complete. But if the job is failed then the job pod will be restarted automatically regardless restartPolicy is OnFailure or Never. But we can deem the job is Failed status if not to updated as Complete after first update.



          Look the my test evidence as follows.



          • Job yaml for testing successful complete


          # vim job.yml
          apiVersion: batch/v1
          kind: Job
          metadata:
          name: pi
          spec:
          parallelism: 1
          completions: 1
          template:
          metadata:
          name: pi
          spec:
          containers:
          - name: pi
          image: perl
          command: ["perl", "-wle", "exit 0"]
          restartPolicy: Never


          • It will show you Complete if it complete the job successfully.


          # oc create -f job.yml &&
          oc get job/pi -o=jsonpath='.status' -w &&
          oc get job/pi -o=jsonpath='.status.conditions[*].type' | grep -i -E 'failed|complete' || echo "Failed"

          job.batch/pi created
          map[startTime:2019-03-09T12:30:16Z active:1]Complete


          • Job yaml for testing failed complete


          # vim job.yml
          apiVersion: batch/v1
          kind: Job
          metadata:
          name: pi
          spec:
          parallelism: 1
          completions: 1
          template:
          metadata:
          name: pi
          spec:
          containers:
          - name: pi
          image: perl
          command: ["perl", "-wle", "exit 1"]
          restartPolicy: Never


          • It will show you Failed if the first job update is not Complete. Test if after delete the existing job resource.


          # oc delete job pi
          job.batch "pi" deleted

          # oc create -f job.yml &&
          oc get job/pi -o=jsonpath='.status' -w &&
          oc get job/pi -o=jsonpath='.status.conditions[*].type' | grep -i -E 'failed|complete' || echo "Failed"

          job.batch/pi created
          map[active:1 startTime:2019-03-09T12:31:05Z]Failed


          I hope it help you. :)






          share|improve this answer























          • i ended up just making a simple script to check the status as you had shown: until [[ $SECONDS -gt $end ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Failed")].status') == "True" ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Complete")].status') == "True" ]]; do

            – ruazn2
            Mar 15 at 23:52












          • That's great, and I'm sorry for showing the openshift cli example. But you can catch up as kubernetes cli, it's great !

            – Daein Park
            Mar 16 at 13:35













          1












          1








          1







          kubectl wait --for=condition=<condition name is waiting for a specific condition, so afaik it can not specify multiple conditions at the moment.



          My workaround is using oc get --wait, --wait is closed the command if the target resource is updated. I will monitor status section of the job using oc get --wait until status is updated. Update of status section is meaning the Job is complete with some status conditions.



          If the job complete successfully, then status.conditions.type is updated immediately as Complete. But if the job is failed then the job pod will be restarted automatically regardless restartPolicy is OnFailure or Never. But we can deem the job is Failed status if not to updated as Complete after first update.



          Look the my test evidence as follows.



          • Job yaml for testing successful complete


          # vim job.yml
          apiVersion: batch/v1
          kind: Job
          metadata:
          name: pi
          spec:
          parallelism: 1
          completions: 1
          template:
          metadata:
          name: pi
          spec:
          containers:
          - name: pi
          image: perl
          command: ["perl", "-wle", "exit 0"]
          restartPolicy: Never


          • It will show you Complete if it complete the job successfully.


          # oc create -f job.yml &&
          oc get job/pi -o=jsonpath='.status' -w &&
          oc get job/pi -o=jsonpath='.status.conditions[*].type' | grep -i -E 'failed|complete' || echo "Failed"

          job.batch/pi created
          map[startTime:2019-03-09T12:30:16Z active:1]Complete


          • Job yaml for testing failed complete


          # vim job.yml
          apiVersion: batch/v1
          kind: Job
          metadata:
          name: pi
          spec:
          parallelism: 1
          completions: 1
          template:
          metadata:
          name: pi
          spec:
          containers:
          - name: pi
          image: perl
          command: ["perl", "-wle", "exit 1"]
          restartPolicy: Never


          • It will show you Failed if the first job update is not Complete. Test if after delete the existing job resource.


          # oc delete job pi
          job.batch "pi" deleted

          # oc create -f job.yml &&
          oc get job/pi -o=jsonpath='.status' -w &&
          oc get job/pi -o=jsonpath='.status.conditions[*].type' | grep -i -E 'failed|complete' || echo "Failed"

          job.batch/pi created
          map[active:1 startTime:2019-03-09T12:31:05Z]Failed


          I hope it help you. :)






          share|improve this answer













          kubectl wait --for=condition=<condition name is waiting for a specific condition, so afaik it can not specify multiple conditions at the moment.



          My workaround is using oc get --wait, --wait is closed the command if the target resource is updated. I will monitor status section of the job using oc get --wait until status is updated. Update of status section is meaning the Job is complete with some status conditions.



          If the job complete successfully, then status.conditions.type is updated immediately as Complete. But if the job is failed then the job pod will be restarted automatically regardless restartPolicy is OnFailure or Never. But we can deem the job is Failed status if not to updated as Complete after first update.



          Look the my test evidence as follows.



          • Job yaml for testing successful complete


          # vim job.yml
          apiVersion: batch/v1
          kind: Job
          metadata:
          name: pi
          spec:
          parallelism: 1
          completions: 1
          template:
          metadata:
          name: pi
          spec:
          containers:
          - name: pi
          image: perl
          command: ["perl", "-wle", "exit 0"]
          restartPolicy: Never


          • It will show you Complete if it complete the job successfully.


          # oc create -f job.yml &&
          oc get job/pi -o=jsonpath='.status' -w &&
          oc get job/pi -o=jsonpath='.status.conditions[*].type' | grep -i -E 'failed|complete' || echo "Failed"

          job.batch/pi created
          map[startTime:2019-03-09T12:30:16Z active:1]Complete


          • Job yaml for testing failed complete


          # vim job.yml
          apiVersion: batch/v1
          kind: Job
          metadata:
          name: pi
          spec:
          parallelism: 1
          completions: 1
          template:
          metadata:
          name: pi
          spec:
          containers:
          - name: pi
          image: perl
          command: ["perl", "-wle", "exit 1"]
          restartPolicy: Never


          • It will show you Failed if the first job update is not Complete. Test if after delete the existing job resource.


          # oc delete job pi
          job.batch "pi" deleted

          # oc create -f job.yml &&
          oc get job/pi -o=jsonpath='.status' -w &&
          oc get job/pi -o=jsonpath='.status.conditions[*].type' | grep -i -E 'failed|complete' || echo "Failed"

          job.batch/pi created
          map[active:1 startTime:2019-03-09T12:31:05Z]Failed


          I hope it help you. :)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 9 at 13:39









          Daein ParkDaein Park

          1,389410




          1,389410












          • i ended up just making a simple script to check the status as you had shown: until [[ $SECONDS -gt $end ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Failed")].status') == "True" ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Complete")].status') == "True" ]]; do

            – ruazn2
            Mar 15 at 23:52












          • That's great, and I'm sorry for showing the openshift cli example. But you can catch up as kubernetes cli, it's great !

            – Daein Park
            Mar 16 at 13:35

















          • i ended up just making a simple script to check the status as you had shown: until [[ $SECONDS -gt $end ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Failed")].status') == "True" ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Complete")].status') == "True" ]]; do

            – ruazn2
            Mar 15 at 23:52












          • That's great, and I'm sorry for showing the openshift cli example. But you can catch up as kubernetes cli, it's great !

            – Daein Park
            Mar 16 at 13:35
















          i ended up just making a simple script to check the status as you had shown: until [[ $SECONDS -gt $end ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Failed")].status') == "True" ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Complete")].status') == "True" ]]; do

          – ruazn2
          Mar 15 at 23:52






          i ended up just making a simple script to check the status as you had shown: until [[ $SECONDS -gt $end ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Failed")].status') == "True" ]] || [[ $(kubectl get jobs $job_name -o jsonpath='.status.conditions[?(@.type=="Complete")].status') == "True" ]]; do

          – ruazn2
          Mar 15 at 23:52














          That's great, and I'm sorry for showing the openshift cli example. But you can catch up as kubernetes cli, it's great !

          – Daein Park
          Mar 16 at 13:35





          That's great, and I'm sorry for showing the openshift cli example. But you can catch up as kubernetes cli, it's great !

          – Daein Park
          Mar 16 at 13:35



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073453%2fwait-for-kubernetes-job-to-complete-on-either-failure-success-using-command-line%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко