<p>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.</p>

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

<p>1) According to the K8S documentation <a href="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/" rel="nofollow noreferrer">here</a>.</p>

<blockquote>
  <p>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.</p>
</blockquote>

<p><a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.12/#cronjobspec-v1beta1-batch" rel="nofollow noreferrer">Here</a> are the details for the failedJobsHistoryLimit property in the CronJobSpec.</p>

<p>This is another way of retaining the details of the failed job for a specific duration. The <code>failedJobsHistoryLimit</code> 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.</p>

<p>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 <code>kubectl job stop</code> will achieve in this case. But, when the Job with a proper image is run with success, I can still see the pod in <code>kubectl get pods</code>. </p>

<p>2) Another approach without using the CronJob is to specify the <code>ttlSecondsAfterFinished</code> as mentioned <a href="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#ttl-mechanism-for-finished-jobs" rel="nofollow noreferrer">here</a>.</p>

<blockquote>
  <p>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.</p>
</blockquote>
