본문으로 건너뛰기

CronJob

1 CronJob

  • 잡 리소스를 생성하면 즉시 해당하는 파드를 실행한다.
    • 그러나 많은 배치 잡이 미래의 특정 시간 또는 지정된 간격으로 반복 실행해야 한다.
  • 쿠버네티스에서는 CronJob을 이용해 잡을 특정 시간 또는 지정된 간격으로 실행할 수 있다.

2 크론잡 생성

apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox:1.28
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
  • 크론잡은 설정된 시간에 잡 템플릿에 따라 잡을 생성한다.

3 Cron schedule syntax

## ┌───────────── minute (0 - 59)
## │ ┌───────────── hour (0 - 23)
## │ │ ┌───────────── day of the month (1 - 31)
## │ │ │ ┌───────────── month (1 - 12)
## │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
## │ │ │ │ │ 7 is also Sunday on some systems)
## │ │ │ │ │ OR sun, mon, tue, wed, thu, fri, sat
## │ │ │ │ │
## * * * * *
EntryDescriptionEquivalent to
@yearly (or @annually)Run once a year at midnight of 1 January0 0 1 1 *
@monthlyRun once a month at midnight of the first day of the month0 0 1 * *
@weeklyRun once a week at midnight on Sunday morning0 0 * * 0
@daily (or @midnight)Run once a day at midnight0 0 * * *
@hourlyRun once an hour at the beginning of the hour0 * * * *