Is there a way to automatically remove completed jobs besides making a cronjob to clean up completed jobs?
The K8s Job Documentation states that the intended behavior of completed jobs is for them to remain in a completed state until manually deleted. Because I am running thousands of jobs a day via k8s cronjobs and I don't want to keep completed jobs around.
i'm using wernight/kubectl's kubectl image
scheduled a cron deleting anything that is
completed
2 - 9 days old
(so I have 2 days to review any failed jobs)it runs every 30mins so i'm not accounting for jobs that are 10+ days old
I've found the below to work
To remove failed jobs:
To remove completed jobs:
A simple way to delete them by running a cron job:
As stated in the documentation "It is up to the user to delete old jobs", see http://kubernetes.io/docs/user-guide/jobs/#job-termination-and-cleanup
I would run a pod to do this cleanup based on job name and certain conditions, thus letting kubernetes at least take care of the availability of your process here. You could run a recurring job for this (assuming you run kubernetes 1.5).
I recently built a kubernetes-operator to do this task.
After deploy it will monitor selected namespace and delete completed jobs/pods if they completed without errors/restarts.
https://github.com/lwolf/kube-cleanup-operator
Using jsonpath: