Home > Back-end >  cronjob can't delete failed pod
cronjob can't delete failed pod

Time:10-23

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.

CodePudding user response:

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.

  • Related