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
## │ │ │ │ │
## * * * * *
Entry | Description | Equivalent to |
---|---|---|
@yearly (or @annually) | Run once a year at midnight of 1 January | 0 0 1 1 * |
@monthly | Run once a month at midnight of the first day of the month | 0 0 1 * * |
@weekly | Run once a week at midnight on Sunday morning | 0 0 * * 0 |
@daily (or @midnight) | Run once a day at midnight | 0 0 * * * |
@hourly | Run once an hour at the beginning of the hour | 0 * * * * |