题目要求
- 用执行命令**’date; echo Hello from the Kubernetes cluster’**的镜像 busybox ,创建一个名为 busybox-job 的 Job 。
- 修改此 Job ,确保在执行时间超过 3000 秒后,kubernetes 会自动终止该 Job。
- 如果容器失败,则尝试重启容器,但最多尝试重启 5 次。
- 检查此Job的日志
参考
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
| kubectl explain job.spec
apiVersion: batch/v1 kind: Job metadata: name: pi spec: template: spec: containers: - name: pi image: perl:5.34.0 command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"] restartPolicy: Never backoffLimit: 4
|
解答
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| apiVersion: batch/v1 kind: Job metadata: name: **busybox-job** spec: activeDeadlineSeconds: 3000 template: spec: containers: - name: **busybox-job** image: busybox command: ["**date;","echo Hello from the Kubernetes cluster**"] restartPolicy: OnFailure backoffLimit: 5
kubectl apply -f 28-jobs.yaml
kubectl get job NAME COMPLETIONS DURATION AGE busybox-job 0/1 6s 6s
|