Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to stop a job in Kubernetes without deleting it

Tags:

Because Kubernetes handles situations where there's a typo in the job spec, and therefore a container image can't be found, by leaving the job in a running state forever, I've got a process that monitors job events to detect cases like this and deletes the job when one occurs.

I'd prefer to just stop the job so there's a record of it. Is there a way to stop a job?

like image 437
Brent212 Avatar asked Oct 01 '18 19:10

Brent212


1 Answers

1) According to the K8S documentation here.

Finished Jobs are usually no longer needed in the system. Keeping them around in the system will put pressure on the API server. If the Jobs are managed directly by a higher level controller, such as CronJobs, the Jobs can be cleaned up by CronJobs based on the specified capacity-based cleanup policy.

Here are the details for the failedJobsHistoryLimit property in the CronJobSpec.

This is another way of retaining the details of the failed job for a specific duration. The failedJobsHistoryLimit property can be set based on the approximate number of jobs run per day and the number of days the logs have to be retained. Agree that the Jobs will be still there and put pressure on the API server.

This is interesting. Once the job completes with failure as in the case of a wrong typo for image, the pod is getting deleted and the resources are not blocked or consumed anymore. Not sure exactly what kubectl job stop will achieve in this case. But, when the Job with a proper image is run with success, I can still see the pod in kubectl get pods.

2) Another approach without using the CronJob is to specify the ttlSecondsAfterFinished as mentioned here.

Another way to clean up finished Jobs (either Complete or Failed) automatically is to use a TTL mechanism provided by a TTL controller for finished resources, by specifying the .spec.ttlSecondsAfterFinished field of the Job.

like image 182
Praveen Sripati Avatar answered Sep 29 '22 12:09

Praveen Sripati