CronJob
Imagine a virtual timekeeper, ticking along to the Linux system's crontab, triggering particular tasks to run at the precise time designated. This is the idea behind 'CronJob'.
API Version Cheat Sheet
v1.5-v1.7
batch/v2alpha1
No
v1.8-v1.20
batch/v1beta1
Yes
v1.21+
batch/v1
Yes
A word of caution: when executing APIs that aren't activated by default, users must configure --runtime-config=batch/v2alpha1 in the kube-apiserver.
CronJob Specs
.spec.scheduleoutlines the schedule of task execution, akin to the Cron format..spec.jobTemplatelists the tasks that need running, and mirrors the Job format..spec.startingDeadlineSecondsspecifies the deadline for initiating tasks..spec.concurrencyPolicydelineates the policy for task concurrency, providing three options: Allow, Forbid, and Replace.
apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailureYou can also use kubectl run to create a CronJob:
Additional Resources
最后更新于