Complete Kubernetes Jobs when one container complete

7/16/2017

Is it possible to have a Job that compete when a container complete?

For exemple, I want to run a Job of one pod with 2 containers:

  • Elasticsearch container
  • Some Java app container connecting to Elasticsearch

The Java app container runs and complete, but obviously the Elasticsearch container continues to run indefinitely.
As a result the Job never completes. What is the solution?

Cheers

-- Joan
kubernetes

3 Answers

7/18/2017

This is probably not the easiest way to do it, but you could use the Kubernetes API to delete the job:

https://kubernetes.io/docs/api-reference/v1.7/#delete-41.

I'm not sure how you're starting the job, or how realistic this solution is in your scenario.

-- markwatsonatx
Source: StackOverflow

7/17/2017

You should look at the livenessProbe capability. This is a capability defined in the deployment, which runs every x seconds while your container is running, to make sure it is running correctly. When a liveness probe fails, Kubernetes will terminate the container. Here is the official Kubernetes documentation on liveness and readiness probes.

The strategy here would be to use the liveness probe on the Elasticsearch container to check that the Java app has a connection to it. As soon as the java app completes, the connection will no longer be there, causing the liveness probe to fail, and kubernetes will terminate the Elasticsearch container.

Look out though, I think kubectl tries to restart the container if it is terminated by a liveness probe failure. You might want to look into disabling that or something.

-- Lindsay Landry
Source: StackOverflow

7/17/2017

Not sure about your uses case. My understanding is Elasticsearch should be running all the time to query the data.

See you can run two different pods. One for Elasticsearch and another one for your java application. just call java application from your job.

-- sfgroups
Source: StackOverflow