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

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


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.


Not really, no such mechanism exists in Kubernetes yet afaik.

You can workaround is to ssh into the machine and run a: (if you're are using Docker)

# Save the logs$ docker log <container-id-that-is-running-your-job> 2>&1 > save.log$ docker stop <main-container-id-for-your-job>

It's better to stream log with something like Fluentd, or logspout, or Filebeat and forward the logs to an ELK or EFK stack.

In any case, I've opened this


You can suspend cronjobs by using the suspend attribute. From the Kubernetes documentation:

https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#suspend