How to fail a cron job after a certain number of retries

0 votes

I have a kubernetes cluster of web scrapping cron job set up.Everything works fine until a cron job fails to start.

Whats the issue?

Here is the config for reference:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: scrape-al
spec:
  schedule: '*/15 * * * *'
  concurrencyPolicy: Allow
  failedJobsHistoryLimit: 0
  successfulJobsHistoryLimit: 0
  jobTemplate:
    metadata:
      labels:
        app: scrape
        scrape: al
    spec:
      template:
        spec:
          containers:
            - name: scrape-al
              image: 'govhawk/openstates:1.3.1-beta'
              command:
                - /opt/openstates/openstates/pupa-scrape.sh
              args:
                - al bills --scrape
          restartPolicy: Never
      backoffLimit: 3
Sep 17, 2018 in Kubernetes by Hannah
• 18,520 points
3,115 views

1 answer to this question.

0 votes

You're trying to set 3 asbackoffLimit of your Job. That means when a Job is created by CronJob, It will retry 3 times if fails. This controls Job, not CronJob

You need to suspend CronJob so than it stop scheduling new Job.

Suspend: true

You can do this manually. If you do not want to do this manually, you need to setup a watcher, that will watch your CronJob status, and will update CronJob to suspend if necessary.

answered Sep 17, 2018 by Kalgi
• 52,350 points

Related Questions In Kubernetes

0 votes
1 answer

How to determine what is the status of a deployment ?

You could use kubectl get deployment <deployment>.  If ...READ MORE

answered Jul 12, 2019 in Kubernetes by Sirajul
• 59,230 points
660 views
0 votes
1 answer

How do i tie a service to a pod or a set of pods?

By declaring pods with the label(s) and ...READ MORE

answered Jul 16, 2019 in Kubernetes by Sirajul
• 59,230 points
1,765 views
0 votes
1 answer

How to use gravitational teleport in a container/kubernetes environment?

You can use teleport to augment kubernetes ...READ MORE

answered Jun 28, 2018 in Kubernetes by ajs3033
• 7,300 points
2,467 views
+1 vote
1 answer

Run a cron job once in N hours

If you want your cron job to ...READ MORE

answered Sep 18, 2018 in Kubernetes by Kalgi
• 52,350 points
853 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,477 views
0 votes
1 answer

permissions related to AWS ECR

if you add allowContainerRegistry: true, kops will add those permissions ...READ MORE

answered Oct 9, 2018 in Kubernetes by Kalgi
• 52,350 points
1,396 views
0 votes
2 answers

Is there a way to start a cron job manually

You can create a simple job based ...READ MORE

answered Sep 18, 2018 in Kubernetes by Nilesh
• 7,060 points
10,768 views
0 votes
1 answer

Connect to existing pod, execute script, disconnect - Kubernetes cron job

As far as i know there's no ...READ MORE

answered Sep 17, 2018 in Kubernetes by Kalgi
• 52,350 points
4,813 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP