1

I have a cronjob which run once every midnight, however one day I deployed wrong version of it and consequently the pod it made went failed soon.

So.. the problem is when I delete the failed pod the cronjob immediately recreates it. How can I stop it? Well anyhow its image is already broken so however it recreates new pod again and again it'd go fail.

my question is "How can I delete failed pod created by cronjob?"

P.S. I'm using rancher but I'm not sure my problem is related to it.

0xF4D3C0D3
  • 747
  • 1
  • 5
  • 15
  • Which kubernetes cluster version is used? I see in comments below `1.16`, if this is true, it won't be addressed at all. – moonkotte Oct 22 '21 at 07:22

1 Answers1

1

my question is "How can I delete failed pod created by cronjob?"

You can use ttlSecondsAfterFinished to control how long you want to keep either Complete or Failed job in your cluster.

apiVersion: batch/v1
kind: CronJob
metadata:
  ...
spec:
  schedule: ...
  ...
  jobTemplate:
    spec:
      ttlSecondsAfterFinished: 43200 <-- example 12 hrs. 0 to clean immediately.
      template:
      ...

Another thing to note this is a K8s v1.21 beta feature at the point of this writing.

gohm'c
  • 13,492
  • 1
  • 9
  • 16
  • but does it keep any history? if `failedJobsHistoryLimit` is 0, how can I troubleshoot failed job? – 0xF4D3C0D3 Oct 22 '21 at 02:07
  • 1
    Adjusted to your comment. K8s v1.16 has long gone EOL and will not be address here. Since you actually want to keep failed job for awhile to troubleshoot, you can adjust `ttlSecondsAfterFinished` alone will do. – gohm'c Oct 22 '21 at 02:58
  • This didn't work for me. I had to delete the job associated with the pod. – mlissner Feb 28 '23 at 15:42