6

I have problems to delete automatically the completed jobs which were started by a CronJob. As I read in this QA here and here, and in the official documentation, this can be done establishing the job history limit .spec.successfulJobsHistoryLimit and .spec.failedJobsHistoryLimit. I have done it, and it is established to 1 for both cases. But my cluster is saving more than 1 completed job, in fact, it is saving more than the default which is 3 successful jobs and 1 for failed jobs.

My current CronJob configuration is

 apiVersion: batch/v1beta1
 kind: CronJob
 metadata:
    name: some-name-cron
 spec:
   schedule: "00 05 1/1 * ?"
   successfulJobsHistoryLimit: 1
   failedJobsHistoryLimit: 1
   jobTemplate:
     spec: ...

And my versions are: - Client version: Client Version: version.Info{Major:"1", Minor:"9", - Server version: Server Version: version.Info{Major:"1", Minor:"8+",

So, what I am doing wrong?

I've attached a image with the k8s dashboard.

Dashboard screenshot with the completed Jobs and Pods

J. Sebio
  • 114
  • 1
  • 1
  • 8

1 Answers1

5

You can use jobs history limits successfulJobsHistoryLimit and failedJobsHistoryLimit to set how many completed and failed jobs should be kept.

You can check for more details on it in the Kubernetes docs here:

Kubernetes - Cronjob: Jobs History Limits

cryotek
  • 508
  • 2
  • 9
  • 2
    I'm using `successfulJobsHistoryLimit` and` failedJobsHistoryLimit` in the CronJob specification as is shown in the attached code in https://stackoverflow.com/questions/48757277/how-kubernetes-can-delete-automatically-the-completed-jobs but is not working. – J. Sebio Feb 13 '18 at 22:08
  • If the limits don't work for you, I recommend you to open an issue directly to [Kubernetes Issues on GitHub](https://github.com/kubernetes/kubernetes/issues) – cryotek Feb 19 '18 at 08:59
  • For some reason, the main documentation linked above stopped listing these parameters. But, you can still find them in the API documentation (present at least in versions 1.10-1.12): https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.12/#cronjob-v1beta1-batch – JJC Sep 29 '18 at 18:08
  • I also see the parameters listed here: https://kubernetes.io/docs/tasks/job/#jobs-history-limits – cryotek Oct 01 '18 at 06:09