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
• 14,090 points
74 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
• 40,540 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
• 40,540 points
109 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
• 40,540 points
63 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 in Kubernetes by Sirajul
• 26,320 points
21 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 in Kubernetes by Sirajul
• 26,320 points
24 views
0 votes
1 answer
0 votes
3 answers

Error while joining cluster with node

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

answered Jan 17 in Others by anonymous
2,194 views
+3 votes
1 answer
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
• 40,540 points
263 views