# Kubernetes CronJob .spec.timeZone, CRON_TZ Rejection, and ConcurrencyPolicy Guide

> Configure IANA timezones safely in Kubernetes v1.27+ CronJobs, fix rejected CRON_TZ/TZ prefixes in .spec.schedule, and choose between Forbid and Replace.

- **Canonical URL**: https://opslint.dev/cron/kubernetes-cronjob-timezone-and-concurrency-policy/
- **Category**: `CRON`
- **Interactive Workbench**: [Open in Live Workbench](https://opslint.dev/cron/#expr=15%204%20*%20*%20*&tz=America%2FChicago&dialect=k8s-cronjob)
- **Normative Specifications**: `Kubernetes v1.27+ batch/v1 CronJob .spec.timeZone GA Specification`, `Kubernetes CronJob Validation: Disallowed TZ= / CRON_TZ= in schedule`, `Kubernetes CronJob ConcurrencyPolicy (Allow, Forbid, Replace)`

## Incident Symptom & Root Cause

**Production Symptom**: Applying a Kubernetes CronJob with CRON_TZ=America/Chicago 15 4 * * * fails validation (or causes unsupported parser drift), or leaving default concurrencyPolicy: Allow spawns dozens of overlapping pods when an upstream database slows down.

**Protocol / Engine Root Cause**: Kubernetes officially prohibits embedding TZ= or CRON_TZ= inside .spec.schedule (which was an undocumented robfig/cron library side effect prior to v1.25) and defaults concurrencyPolicy to Allow alongside pod restartPolicy: OnFailure, creating runaway pod storms when jobs hang.

## Remediation Diff (Broken vs Verified Fix)

### Invalid CRON_TZ Prefix + Unsafe Default Concurrency

```text
apiVersion: batch/v1
kind: CronJob
metadata:
  name: warehouse-etl-sync
spec:
  # Rejected by K8s API validation: CRON_TZ prefix is unsupported!
  schedule: "CRON_TZ=America/Chicago 0 */1 * * *"
  # Omitted concurrencyPolicy defaults to "Allow" -> overlapping ETL corruption!
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: OnFailure
          containers:
            - name: sync
              image: registry.internal/etl:1.9.0
```

### Native .spec.timeZone + Bounded Forbid & activeDeadlineSeconds

```text
apiVersion: batch/v1
kind: CronJob
metadata:
  name: warehouse-etl-sync
spec:
  schedule: "5 * * * *"
  timeZone: "America/Chicago"
  concurrencyPolicy: Forbid
  startingDeadlineSeconds: 300
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      # Hard cap runtime at 50m so a hung pod cannot block Forbid forever!
      activeDeadlineSeconds: 3000
      backoffLimit: 2
      template:
        spec:
          restartPolicy: Never
          containers:
            - name: sync
              image: registry.internal/etl:1.9.0
              env:
                - name: TZ
                  value: "America/Chicago"
```

## Engineering Deep Dive

Since Kubernetes v1.27 (when CronJobTimeZone graduated to GA), .spec.timeZone accepts any valid IANA timezone database string (such as America/Chicago, Asia/Tokyo, or Etc/UTC) and instructs kube-controller-manager to calculate trigger times in that zone. Crucially, setting .spec.timeZone on the CronJob ONLY tells the control-plane scheduler when to create the Job—it does NOT set the TZ environment variable inside your container! If your application logs or SQL queries expect local time, pass env: [{ name: 'TZ', value: 'America/Chicago' }] inside the Pod spec too (or better, keep application internals in UTC).

Choosing concurrencyPolicy requires pairing it with jobTemplate.spec.activeDeadlineSeconds. With the default Allow, an ETL job running every 5 minutes against a locked table spawns 12 concurrent pods per hour until connection pools collapse. Switching to Forbid skips new ticks while a previous Job is still active—but if a pod deadlocks on a network socket without a timeout, Forbid will silently skip every subsequent run forever! Setting activeDeadlineSeconds ensures Kubernetes terminates hung pods and unblocks the next scheduled cycle.

Reserve concurrencyPolicy: Replace only for stateless cache warmers or read-only snapshot jobs that safely handle SIGTERM mid-flight. Under Replace, if the previous Job is still running when the next schedule fires, Kubernetes deletes the active Job (sending SIGTERM to pods) and immediately starts a fresh replacement.

## Kubernetes CronJob Concurrency & Timezone Configuration Matrix

| Case / Engine | Protocol Behavior | Production Remediation |
| :--- | :--- | :--- |
| **concurrencyPolicy: Allow (Default)** (`#k8s-concurrency-allow`) | Starts new Job pods on schedule even when prior runs are still executing. | Safe ONLY for completely independent, stateless, fast fan-out tasks; dangerous for DB migrations or ETL. |
| **concurrencyPolicy: Forbid** (`#k8s-concurrency-forbid`) | Skips the new scheduled run if the previous Job has not yet completed or failed. | Always combine with jobTemplate.spec.activeDeadlineSeconds so one hung pod cannot stall the CronJob indefinitely. |
| **concurrencyPolicy: Replace** (`#k8s-concurrency-replace`) | Terminates any currently active Job and creates a new Job at the scheduled tick. | Ensure container handles SIGTERM cleanly and performs atomic writes or rollbacks. |
| **.spec.timeZone vs container env TZ** (`#k8s-spec-timezone-vs-pod-tz`) | .spec.timeZone controls kube-controller-manager trigger times only; pods still default to UTC. | Set .spec.timeZone for scheduling AND explicit container TZ env if user-facing reports format local dates. |

## Frequently Asked Engineering Questions

### What happens if node tzdata inside kube-controller-manager is outdated when a country changes DST laws?

Kubernetes evaluates .spec.timeZone using the timezone database compiled into or mounted by kube-controller-manager on the control plane. Managed clusters (EKS, GKE, AKS) patch control-plane tzdata automatically; self-hosted kubeadm clusters must keep control-plane OS tzdata packages updated.

### Why should CronJob pods often use restartPolicy: Never instead of OnFailure?

With restartPolicy: OnFailure, a crashing container restarts in-place on the same node (which may have a full disk or broken CNI) and hides previous container logs once rotated. With restartPolicy: Never and backoffLimit: 2, Kubernetes schedules retry pods onto healthy nodes while preserving failed pod logs up to failedJobsHistoryLimit.

### Does Kubernetes CronJob support @hourly, @daily, and @monthly macros?

Yes. robfig/cron in Kubernetes supports standard Vixie macros (@yearly, @monthly, @weekly, @daily, @hourly), mapping @daily to 0 0 * * * in the configured .spec.timeZone.

## Related Problem-Cluster Guides

- [Fix Kubernetes CronJob TooManyMissedTimes (100 Missed Schedules Limit)](https://opslint.dev/cron/kubernetes-starting-deadline-seconds-missed-runs/) — Understand how Kubernetes CronJob calculates missed runs from lastScheduleTime, why 100 missed ticks halt scheduling, and how to tune startingDeadlineSeconds.
- [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 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.
- [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.
