Kubernetes error L, #, W or H
failed to parse int from L: strconv.Atoi: parsing "L": invalid syntax
spec.schedule: Invalid value: "0 0 L * *": failed to parse int from L: strconv.Atoi: parsing "L": invalid syntaxspec.schedule: Invalid value: "0 9 * * MON#1": failed to parse int from MON#1: strconv.Atoi: parsing "MON#1": invalid syntaxMessage produced by running the expression through robfig/cron v3.0.1, the parser and version Kubernetes validates .spec.schedule with.
What it means
The parser understands numbers, names (JAN, MON), *, ?, ranges, lists and steps. Anything else reaches Go’s integer parser and fails there. The usual sources are Quartz and EventBridge’s L, W and #, and Jenkins’ H.
Kubernetes has no way to say “last day” or “first Monday” in one expression. The usual workaround is a broader schedule plus a date check at the start of the job; the linked pages have tested versions.
Rejected expressions and their fixes
Each expression opens in the tester. The message under a rejected one is what robfig/cron v3.0.1 printed for it.
-
InsteadNo single Kubernetes expressionTested workaround
Last day of the month. Run on days 28 to 31 and exit unless tomorrow is the 1st.
-
InsteadNo single Kubernetes expressionTested workaround
First Monday of the month. Run every Monday and exit unless the date is 7 or lower.
-
InsteadNo single Kubernetes expressionTested workaround
Last Friday of the month. Run every Friday and exit unless next week is in another month.
-
Use17 0 * * *At 00:17.
Jenkins’
Hpicks a stable minute per job. Here you pick it yourself; a minute other than 0 avoids the top-of-the-hour rush.
Questions
- How do I run a Kubernetes CronJob on the last day of the month?
- Schedule it for days 28 to 31 with
0 0 28-31 * *and have the job exit unless tomorrow is the 1st. The last-day-of-month page has the check. - Why can’t I use
1-7withMONfor the first Monday? - Kubernetes runs a job when either day field matches, so
0 9 1-7 * MONruns on the 1st to the 7th and on every Monday. Azure is the dialect where both must match.
Other Kubernetes errors
- expected exactly 5 fields, found 6: [0 0 12 * * ?]Kubernetes: Six or seven fields
- end of range (7) above maximum (6): 7Kubernetes: Sunday written as 7
- beginning of range (0) below minimum (1): 0Kubernetes: Day or month written as 0
- beginning of range (22) beyond end of range (2): 22-2Kubernetes: A range that wraps around
- cannot use TZ or CRON_TZ in schedule, use timeZone field insteadKubernetes:
TZ=orCRON_TZ=in the schedule