CronJob 시작 마감 시간 점검

늦은 실행을 허용할 범위를 작업의 시간 요구사항에 맞게 정하세요.

설명

starting_deadline_seconds는 예정 시각을 놓친 뒤 컨트롤러가 몇 초까지 새 Job을 생성할 수 있는지 정합니다. 늦게 생성해도 된다면 생략할 수 있지만 누락된 작업이 모두 재실행되지는 않을 수 있습니다.

잠재적 영향

기한이 너무 길면 오래된 작업이 현재 데이터에 영향을 줄 수 있습니다. 너무 짧으면 일반적인 컨트롤러 지연에도 실행을 건너뛸 수 있습니다.

해결 방법

업무상 허용할 시작 지연을 정하고 컨트롤러가 약 10초마다 확인한다는 점을 고려하세요. 중복 실행과 재시도에도 문제가 없도록 작업을 설계하고 concurrency_policy를 확인하세요. 실행 중인 Job의 시간 제한은 active_deadline_seconds로 설정하세요.

예시

변경 후 값 10은 컨트롤러가 Job을 생성할 수 있는 기한입니다. 파드는 그보다 늦게 시작할 수 있습니다. 현재 CronJob API에는 kubernetes_cron_job_v1을 사용하세요.

변경 전

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"]
            }
          }
        }
      }
    }
  }
}

변경 후

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"]
            }
          }
        }
      }
    }
  }
}

참조