# Fix Kubernetes CronJob TooManyMissedTimes (100 Missed Schedules Limit)

> Understand how Kubernetes CronJob calculates missed runs from lastScheduleTime, why 100 missed ticks halt scheduling, and how to tune startingDeadlineSeconds.

- **Canonical URL**: https://opslint.dev/cron/kubernetes-starting-deadline-seconds-missed-runs/
- **Category**: `CRON`
- **Interactive Workbench**: [Open in Live Workbench](https://opslint.dev/cron/#expr=*%2F1%20*%20*%20*%20*&tz=UTC&dialect=k8s-cronjob)
- **Normative Specifications**: `Kubernetes CronJob Concepts: Starting Deadline & Missed Schedules`, `kube-controller-manager cronjob_controllerv2 (100 Missed Runs Cap)`

## Incident Symptom & Root Cause

**Production Symptom**: After suspending a high-frequency CronJob over a weekend (suspend: true -> false) or recovering from a control-plane outage, the CronJob refuses to create any new pods and emits Warning TooManyMissedTimes: 'Cannot determine if job needs to be started. Too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.'

**Protocol / Engine Root Cause**: When startingDeadlineSeconds is unset, the Kubernetes CronJob controller counts missed schedule ticks all the way back to .status.lastScheduleTime. If more than 100 scheduled intervals elapsed (for example 101 minutes on a * * * * * CronJob), the controller aborts scheduling for that tick and logs an error rather than flooding the cluster.

## Remediation Diff (Broken vs Verified Fix)

### 1-Minute CronJob Without startingDeadlineSeconds

```text
apiVersion: batch/v1
kind: CronJob
metadata:
  name: queue-outbox-poller
spec:
  schedule: "*/1 * * * *"
  # Unset startingDeadlineSeconds!
  # If suspended or offline for >100 minutes, un-suspending triggers TooManyMissedTimes!
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: Never
          containers:
            - name: poller
              image: registry.internal/outbox-poller:1.2.0
```

### Bounded startingDeadlineSeconds Window (200s < 100 Ticks)

```text
apiVersion: batch/v1
kind: CronJob
metadata:
  name: queue-outbox-poller
spec:
  schedule: "*/1 * * * *"
  # Controller only counts missed ticks within the last 200 seconds (~3 ticks << 100!)
  # Must be >= 10s because CronJob controller reconciles every 10 seconds.
  startingDeadlineSeconds: 200
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      activeDeadlineSeconds: 55
      template:
        spec:
          restartPolicy: Never
          containers:
            - name: poller
              image: registry.internal/outbox-poller:1.2.0
```

## Engineering Deep Dive

Kubernetes CronJob controller v2 runs a reconciliation loop roughly every 10 seconds. For each CronJob, it inspects the window from status.lastScheduleTime (or the CronJob creation timestamp) up to 'now'. If startingDeadlineSeconds is omitted, that lookback window is unbounded—so a per-minute CronJob that was paused for two hours accumulates 120 missed schedules, crossing the hardcoded 100-missed-runs safety fuse.

Setting startingDeadlineSeconds changes the lookback boundary dramatically! When startingDeadlineSeconds is set (say to 200 seconds), the controller ONLY counts missed schedules inside the last 200 seconds instead of all the way back to lastScheduleTime. On a 1-minute CronJob, at most 3 schedules can ever fit inside 200 seconds, making it mathematically impossible to hit the >100 missed-schedules error after un-suspending a job or recovering from downtime!

One critical minimum bound applies: never set startingDeadlineSeconds below 10 seconds! Because kube-controller-manager scans CronJobs on a 10-second tick, setting startingDeadlineSeconds: 5 means a job scheduled at 12:00:00 examined by the controller at 12:00:07 has already missed its 5-second deadline and will be permanently skipped almost every run. Keep startingDeadlineSeconds between 60 and 600 seconds for minute-level jobs, and 900 to 3600 seconds for hourly or daily batch jobs.

## startingDeadlineSeconds Sizing Guide by Cron Frequency

| Case / Engine | Protocol Behavior | Production Remediation |
| :--- | :--- | :--- |
| **startingDeadlineSeconds < 10** (`#deadline-under-10s-trap`) | CronJob skips most or all runs because the controller's 10-second sync loop arrives after the deadline expires. | Always set startingDeadlineSeconds >= 60 (minimum safe floor above 10s controller sync). |
| **Every 1 minute (*/1 * * * *)** (`#deadline-every-1-min`) | Unset deadline hits >100 missed limit after 1h 41m of suspension or control-plane outage. | Set startingDeadlineSeconds: 180 (caps lookback at 3 ticks, prevents TooManyMissedTimes). |
| **Every 5 minutes (*/5 * * * *)** (`#deadline-every-5-min`) | Unset deadline hits >100 missed limit after 8h 25m of suspension. | Set startingDeadlineSeconds: 300 to 600. |
| **Daily batch (0 4 * * *)** (`#deadline-daily-batch`) | Late start hours after maintenance window could collide with peak daytime traffic. | Set startingDeadlineSeconds: 3600 (allow up to 1h late catch-up, skip if outage lasted longer). |

## Frequently Asked Engineering Questions

### How do I recover an existing CronJob stuck in TooManyMissedTimes without deleting job history?

Patch the CronJob to add spec.startingDeadlineSeconds (for example kubectl patch cronjob <name> -p '{"spec":{"startingDeadlineSeconds":300}}'). On the very next 10-second controller pass, the lookback window shrinks to 300 seconds and normal scheduling resumes immediately.

### If 4 runs were missed inside startingDeadlineSeconds, will Kubernetes launch 4 catch-up pods at once?

No. Even when multiple ticks fall inside startingDeadlineSeconds, Kubernetes CronJob controller only schedules a single catch-up Job representing the most recent missed schedule time.

### Does suspend: true update lastScheduleTime while paused?

No. While spec.suspend is true, lastScheduleTime remains frozen at the last run prior to suspension, which is why un-suspending a job without startingDeadlineSeconds frequently triggers TooManyMissedTimes.

## Related Problem-Cluster Guides

- [Kubernetes CronJob .spec.timeZone, CRON_TZ Rejection, and ConcurrencyPolicy Guide](https://opslint.dev/cron/kubernetes-cronjob-timezone-and-concurrency-policy/) — Configure IANA timezones safely in Kubernetes v1.27+ CronJobs, fix rejected CRON_TZ/TZ prefixes in .spec.schedule, and choose between Forbid and Replace.
- [Cron Jobs Skipped During Daylight Saving Time Spring Forward (02:00–02:59 Gap)](https://opslint.dev/cron/dst-spring-forward-skipped-jobs/) — Why 02:30 local cron schedules vanish on Kubernetes CronJob and AWS EventBridge while Vixie Cron runs catch-up at 03:00, and how to prevent missed runs.
- [Prevent Overlapping Cron Jobs with Linux flock -n Non-Blocking Locks](https://opslint.dev/cron/flock-prevent-overlapping-cron-flock-wrappers/) — Stop runaway duplicate cron processes and database lock pileups using kernel-managed util-linux flock -n file descriptors instead of brittle PID files.
- [Prevent Duplicate Cron Execution During Daylight Saving Time Fall Back (01:00–01:59 Overlap)](https://opslint.dev/cron/dst-fall-back-duplicate-execution/) — Diagnose and prevent double-firing cron jobs during the November DST fall-back hour across Kubernetes CronJob, Vixie Cron, and AWS EventBridge.
