Review CronJob start deadlines

Choose an allowed start delay that matches the job’s timing requirements.

Description

starting_deadline_seconds limits how late the controller can create a Job after a missed schedule. You can omit it if late Jobs are acceptable. Missed runs are not guaranteed to be replayed.

Potential impact

A long delay may let a stale job change current data. A very short deadline can skip runs during normal controller delays.

Remediation

Choose the delay your task can tolerate, allowing for the controller’s roughly ten-second check interval. Make the job safe to repeat and review retries and concurrency_policy. To limit a running Job’s duration, set its active_deadline_seconds.

Examples

The example gives the controller 10 seconds to create a missed Job. Its Pods may start later. Use kubernetes_cron_job_v1 with the current CronJob API.

Before

hcl
resource "kubernetes_cron_job" "example" {
  metadata {
    name = "demo"
  }

  spec {
    schedule = "1 0 * * *"

    job_template {
      metadata {}
      spec {
        template {
          metadata {}
          spec {
            container {
              name    = "hello"
              image   = "busybox"
              command = ["/bin/sh", "-c", "date; echo Hello from the Kubernetes cluster"]
            }
          }
        }
      }
    }
  }
}

After

hcl
resource "kubernetes_cron_job" "example" {
  metadata {
    name = "demo"
  }

  spec {
    schedule                  = "1 0 * * *"
    starting_deadline_seconds = 10

    job_template {
      metadata {}
      spec {
        template {
          metadata {}
          spec {
            container {
              name    = "hello"
              image   = "busybox"
              command = ["/bin/sh", "-c", "date; echo Hello from the Kubernetes cluster"]
            }
          }
        }
      }
    }
  }
}

References