Is there a way to automatically delete completed jobs other than creating a cronjob to clear completed jobs?
The K8s documentation states that the intended behavior of completed jobs is to remain in a completed state until manually deleted. Because I do thousands of tasks a day through k8s cronjobs, and I don't want completed tasks to be completed.
Now you can set limits on the history or completely disable the history so that unsuccessful or successful tasks are not supported endlessly. See my answer here . The documentation is here .
An easy way to remove them by running the cron job:
kubectl get jobs --all-namespaces | sed '1d' | awk '{ print $2, "--namespace", $1 }' | while read line; do kubectl delete jobs $line; done
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 pod to do this cleanup based on the name of the job and certain conditions, which would allow the kubernets to at least take care of the availability of your process here. You can run repetitive work for this (assuming you run the 1.5 kubernets).
I recently built a kubernet operator to accomplish this task.
After deployment, it will monitor the selected namespace and delete completed jobs / containers if they are completed without errors / restart.
https://github.com/lwolf/kube-cleanup-operator