Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set retention policy for Pods created by Kubernetes CronJob

I understand that Kubernetes CronJobs create pods that run on the schedule specified inside the CronJob. However, the retention policy seems arbitrary and I don't see a way where I can retain failed/successful pods for a certain period of time.

like image 708
bholagabbar Avatar asked Mar 18 '19 11:03

bholagabbar


People also ask

How do you configure a Kubernetes job so that pods are retained after completion?

How do you configure a Kubernetes Job so that Pods are retained after completion? a) Configure the backofflimit parameter with a non-zero value. b) Set a startingDeadlineSeconds value high enough to allow you to access the logs. c) Configure the cascade flag for the Job with a value of false.

How do I disable CronJobs in Kubernetes?

Edit your current cronjob resource to include the . spec. suspend field and set it to true. Any currently running jobs will complete but future jobs will be suspended.


1 Answers

I am not sure about what you are exactly asking here.

CronJob does not create pods. It creates Jobs (which also manages) and those jobs are creating pods. As per Kubernetes Jobs Documentation 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. In short, pods and jobs will not be deleted utill you remove CronJob. You will be able to check logs from Pods/Jobs/CronJob. Just use kubctl describe

As default CronJob keeps history of 3 successfulJobs and only 1 of failedJob. You can change this limitation in CronJob spec by parameters:

spec:
  successfulJobsHistoryLimit 10
  failedJobsHistoryLimit 0

0 means that CronJob will not keep any history of failed jobs
10 means that CronJob will keep history of 10 succeeded jobs

You will not be able to retain pod from failed job because, when job fails it will be restarted until it was succeded or reached backoffLimit given in the spec.

Other option you have is to suspend CronJob.

kubctl patch cronjob <name_of_cronjob> -p '{"spec:"{"suspend":true}}'

If value of spuspend is true, CronJob will not create any new jobs or pods. You will have access to completed pods and jobs.

If none of the above helpd you, could you please give more information what do you exactly expect?
CronJob spec would be helpful.

like image 74
PjoterS Avatar answered Oct 25 '22 02:10

PjoterS