1

I created a CronJob by using below yaml file.

kind: CronJob
metadata:
  name: $DEPLOY_NAME
spec:
  # Run the job once a day at 8 PM
  schedule: "0 20 * * *"
  # If the previous job is not yet complete during the scheduled time, do not start the next job
  concurrencyPolicy: Forbid
  jobTemplate:
      spec:
        # The pods will be available for 3 days (259200 seconds) so that logs can be checked in case of any failures
        ttlSecondsAfterFinished: 259200
        template:
          spec:
            containers:
            - name: $DEPLOY_NAME
              image: giantswarm/tiny-tools
              imagePullPolicy: IfNotPresent
              resources:
                requests:
                  cpu: "0.01"
                  memory: 256Mi
                limits:
                  cpu: "0.5"
                  memory: 512Mi
              command: ["/bin/sh"]
              args: ["-c", "cd /home/tapi && sh entrypoint.sh"]

As mentioned in ttlSecondsAfterFinished, k8s keeps my job in the cluster. However, the pod created by the job (after completion) gets deleted after sometime.

As per garbage collection policy, my pod object should be dependent upon my job. And since job object is not garbage collected, my pod object should also remain alive. Am i missing something?

Manish Bansal
  • 2,400
  • 2
  • 21
  • 37

1 Answers1

1

The .spec.successfulJobsHistoryLimit and .spec.failedJobsHistoryLimit fields are optional. These fields specify how many completed and failed jobs should be kept. By default, they are set to 3 and 1 respectively.

You might need to set these fields to appropriate value

Dherik
  • 17,757
  • 11
  • 115
  • 164
P Ekambaram
  • 15,499
  • 7
  • 34
  • 59
  • Although, when i check `kubectl get jobs`, i only see 3 jobs. But if i check ` kubectl describe cronjob abc`, failedjobhistortlimit is coming as 1. But success limit is coming as very high number as 824638391724 – Manish Bansal Nov 15 '19 at 17:15
  • You need to describe the job that is completed – P Ekambaram Nov 15 '19 at 17:53
  • That also i did. But there is no events in that. Please tell me what else should i check in that. In job,. There is no success and failure limits defined. – Manish Bansal Nov 16 '19 at 02:10