如果你这样做kubectl describe cj <name_of_cronjob>
,它会告诉你Last Schedule Time
Last Schedule Time: Tue, 07 May 2019 16:58:00 +0200
您还将看到以下事件:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 2m25s cronjob-controller Created job hello-1
Normal SawCompletedJob 2m15s cronjob-controller Saw completed job: hello-1
Normal SuccessfulCreate 85s cronjob-controller Created job hello-2
Normal SawCompletedJob 75s cronjob-controller Saw completed job: hello-2
Normal SuccessfulCreate 24s cronjob-controller Created job hello-3
Normal SawCompletedJob 14s cronjob-controller Saw completed job: hello-3
您可以date
在开头添加命令,CronJob
它会在启动时在日志中告诉您。
Yaml 可能如下所示:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
您可以检查将显示data
正在执行的日志。
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-1-nrf5b 0/1 Completed 0 3m
hello-2-kk8t5 0/1 Completed 0 119s
hello-3-tpffz 0/1 Completed 0 59s
$ kubectl logs pods/hello-2-kk8t5
Tue May 7 14:58:09 UTC 2019
Hello from the Kubernetes cluster
您可以在 Kubernetes 文档Running Automated Tasks with a CronJob中查看此示例和其他示例。