题目要求
- 在清单文件 /ckad/CKAD00016/periodic.yaml 中定义此 Pod
- 在一个 busybox:stable 容器中运行命令 date 该命令必须每分钟运行一次,并且必须在 10 秒内完成运行,或者被 Kubernetes 终止运行。注意: CronJob 名称和容器名称都必须为 hello
- 在上述清单文件中创建此资源,并验证此 Job 至少成功执行一次。
参考
https://kubernetes.io/zh-cn/docs/tasks/job/automated-tasks-with-cron-jobs/
https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/job/
解答
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| vim /ckad/CKAD00016/periodic.yaml
apiVersion: batch/v1 kind: CronJob metadata: name: hello spec: schedule: "* * * * *" jobTemplate: spec: template: spec: activeDeadlineSeconds: 10 containers: - name: hello image: busybox:stable imagePullPolicy: IfNotPresent command: - /bin/sh - -c - date restartPolicy: OnFailure
kubectl apply -f /ckad/CKAD00016/periodic.yaml
kubectl get cronjob hello NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE hello * * * * * False 0 47s 3m
kubectl get job | grep hello hello-1708415580 1/1 3s 2m35s hello-1708415640 1/1 2s 94s hello-1708415700 1/1 2s 34s
kubectl get pod | grep hello hello-1708415580-wgtc7 0/1 Completed 0 2m51s hello-1708415640-vq5z7 0/1 Completed 0 110s hello-1708415700-nmxkq 0/1 Completed 0 50s
kubectl logs hello-1708415700-nmxkq Tue Feb 20 07:55:04 UTC 2024
|