当前位置:  首页>> 技术小册>> Kubernets合辑5-Pod控制器

  1. apiVersion: batch/v1beta1
  2. kind: CronJob
  3. metadata:
  4. name: hello
  5. spec:
  6. schedule: "*/1 * * * *"
  7. concurrencyPolicy: Forbid
  8. successfulJobsHistoryLimit: 3
  9. failedJobsHistoryLimit: 10
  10. jobTemplate:
  11. spec:
  12. template:
  13. spec:
  14. containers:
  15. - name: hello
  16. image: busybox
  17. imagePullPolicy: IfNotPresent
  18. args:
  19. - /bin/sh
  20. - -c
  21. - date; echo Hello from the Kubernetes cluster
  22. restartPolicy: OnFailure
  1. [root@centos-7-52 ~]# kubectl apply -f /tmp/cronjob.yaml
  2. [root@centos-7-52 ~]# kubectl get cronjob -o wide #查看cronjob
  3. NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE CONTAINERS IMAGES SELECTOR
  4. hello */1 * * * * False 0 52s 6m36s hello busybox <none>
  5. [root@centos-7-52 ~]# kubectl get job -o wide | grep hello # 查看执行的job历史,Job名称中的数字为时间戳
  6. hello-1607757060 1/1 1s 2m48s hello busybox controller-uid=194350a4-21ca-4d01-b264-34a963e78ce7
  7. hello-1607757120 1/1 1s 108s hello busybox controller-uid=e30a318c-6c0f-4d1d-b200-3dfaffe083c5
  8. hello-1607757180 1/1 1s 48s hello busybox controller-uid=a00d02fc-8d7e-40b3-8e2a-25620ecab427
  9. [root@centos-7-52 ~]# date -d @1607757180
  10. Sat Dec 12 15:13:00 CST 2020

该分类下的相关小册推荐: