Cron Atlas

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 syntax
spec.schedule: Invalid value: "0 9 * * MON#1": failed to parse int from MON#1: strconv.Atoi: parsing "MON#1": invalid syntax

Message 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.

  1. Rejected0 0 L * *failed to parse int from L: strconv.Atoi: parsing "L": invalid syntax
    Instead
    No single Kubernetes expressionTested workaround

    Last day of the month. Run on days 28 to 31 and exit unless tomorrow is the 1st.

  2. Rejected0 9 * * MON#1failed to parse int from MON#1: strconv.Atoi: parsing "MON#1": invalid syntax
    Instead
    No single Kubernetes expressionTested workaround

    First Monday of the month. Run every Monday and exit unless the date is 7 or lower.

  3. Rejected0 17 * * 5Lfailed to parse int from 5L: strconv.Atoi: parsing "5L": invalid syntax
    Instead
    No single Kubernetes expressionTested workaround

    Last Friday of the month. Run every Friday and exit unless next week is in another month.

  4. RejectedH 0 * * *failed to parse int from H: strconv.Atoi: parsing "H": invalid syntax
    Use
    17 0 * * *At 00:17.

    Jenkins’ H picks 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-7 with MON for the first Monday?
Kubernetes runs a job when either day field matches, so 0 9 1-7 * MON runs on the 1st to the 7th and on every Monday. Azure is the dialect where both must match.

Other Kubernetes errors

Reference