this is my kubernetes CronJob definition:
apiVersion: batch/v1
kind: CronJob
metadata:
name: job-monitor
namespace: cronjobs
labels:
app: job-monitor
spec:
schedule: "15 */6 * * *"
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 3
concurrencyPolicy: Replace
jobTemplate:
spec:
template:
spec:
nodeSelector:
agentpool: streaming
restartPolicy: OnFailure
containers:
- name: job-monitor
image: imageRepository:latest
securityContext:
capabilities:
add:
- NET_ADMIN
resources:
requests:
cpu: "2000m"
memory: "4000Mi"
limits:
cpu: "3000m"
memory: "6000Mi"
It gets executed @minute 15 but it get executed more than once so every minute. One day I saw the alert comming every minute @2:15, 2:16, 2:16, 2:18, 2:20 The other day @2:15, 2:16, 2:17, 2:18, 2:21.
Why?
As I checked the above comments and Answer:
You want to run the Job every 6 hours starting at minute 15 of the hour during Mon-Sun. So per day it runs 4 times.
If it starts from 0:15 min, 6:15 min, 12:15 min, 18:15 min again it repeats the same for the next day..
Syntax is:
15 */6 * * 1-7
Output :
I have tried the above cron job syntax and it's working fine.
If you find any errors let me know .
The first item in a cron schedule is the minute. The first * in your cron schedule * 7,19 * * * matches every minute between 7:00 and 7:59 (and also every minute between 19:00 and 19:59). In theory, your cron job should not run twice, but 120 times per day using this schedule. To execute your cron job at exactly 7:00 and 19:00, use 0 7,19 * * * as schedule.
For reference, the Kubernetes documentation on CronJob resources contains more information on the cron schedule format and itself links to the BSD cron documentation .
And also refer to these documents for more information for cron jobs execution .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.