5

What's the best way in script to wait for a job or pod to complete in Kubernetes or Google Container Engine?

In particular, it would be better to be notified rather than polling for status in kubectl, but I'd be happy with a fairly efficient loop without any slips between the cracks. Essentially, I'd like the equivalent of a plain docker run since that blocks until command termination, but I don't want to use docker directly in this case.

I looked at Github Issue #1899 but it looks unresolved as yet.

Glen Low
  • 4,379
  • 1
  • 30
  • 36
  • Possible duplicate of [Tell when Job is Complete](https://stackoverflow.com/questions/44686568/tell-when-job-is-complete) – Aleksi Jul 30 '19 at 09:19

1 Answers1

2

It's not really what it was designed for, but you could run kubectl attach $POD. It'll show you the output of the pod while it's running and automatically terminate once the pod is done running.

Of course, you'll have to handle the error that it prints if the pod is already done running, since it's only really meant for use on pods that are currently running.

Alex Robinson
  • 12,633
  • 2
  • 38
  • 55
  • 1
    So I guess what people do is polling to check for completion? – jonalv Dec 01 '16 at 09:42
  • 1
    I'd also like to know how to handle the case where the pod hasn't started yet, so we need to poll for started-ness before running the `attach` command. – Holly Cummins Oct 22 '17 at 17:37