How to run 2 cron jobs scheduled for every month

0 votes

I want to run two cron jobs to be scheduled every month. The cron jobs are in a JS file. How do I create a job that runs those JS files in the pod running that service every month using Kubernetes ? 

Sep 27, 2018 in Kubernetes by Hannah
• 18,520 points
1,251 views

1 answer to this question.

0 votes

Unfortunately, you cannot run the CronJob inside a container of your application.

The only thing you can do is create a container which will contain your cronjob and necessary environment for running it and schedule to run that pod by a CronJob.

Here is an example of the configuration:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: "*/1 * * * *" # syntax is a same as in system cron jobs
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: image_with_cronjob_code # here is an image with your cronjob
            args:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure
answered Sep 27, 2018 by Kalgi
• 52,350 points

Related Questions In Kubernetes

0 votes
1 answer

How to fail a (cron) job after a certain number of retries?

You're trying to set 3 asbackoffLimit of your Job. ...READ MORE

answered Sep 17, 2018 in Kubernetes by Kalgi
• 52,350 points
3,115 views
0 votes
1 answer

Unable to schedule jobs every couple of days

Yes that is a very weird problem ...READ MORE

answered Sep 19, 2018 in Kubernetes by Kalgi
• 52,350 points
736 views
0 votes
1 answer

Can I configure my kubernetes job to run for a specified time?

When we create a job spec, we ...READ MORE

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

How to configure a default imagePullSecret for any deployment?

Hey @Sam, you can attach an image ...READ MORE

answered Jul 18, 2019 in Kubernetes by Sirajul
• 59,230 points
2,018 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
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,036 views
0 votes
1 answer

Why do jobs have to be idempotent - kubernetes cron jobs

To understand why this happens lets for ...READ MORE

answered Sep 17, 2018 in Kubernetes by Kalgi
• 52,350 points
2,672 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