赞
踩
apiVersion: batch/v1beta1 kind: CronJob metadata: name: test-cronjob spec: schedule: "*/1 * * * *" # 参考定时计划任务(分时日月周) startingDeadlineSeconds: 15 # pod必须在规定时间后的15秒内开始执行,若超过该时间未执行,则任务将不运行,且标记失败 jobTemplate: spec: template: metadata: labels: app: test-cronjob spec: containers: - name: test-job image: busybox args: - "/bin/sh" - "-c" - "date; echo Hello from the Kubernetes cluster" restartPolicy: OnFailure
查看创建的CronJob:
[root@k8s-master ~]# kubectl get cronjob
等待1分钟可以查看执行的任务(Jobs):
[root@k8s-master ~]# kuberctl get jobs
apiVersion: batch/v1beta1 kind: CronJob metadata: labels: run: hello name: hello namespace: default spec: concurrencyPolicy: Allow # 并发策略 failedJobsHistoryLimit: 1 # 要保留的失败的完成作业数(默认为1) schedule: '*/1 * * * *' # 作业时间表。在此示例中,作业将每分钟运行一次 successfulJobsHistoryLimit: 3 # 要保留的成功完成的作业数(默认为3) terminationGracePeriodSeconds: 30 # job存活时间 默认不设置为永久 jobTemplate: # 作业模板。这类似于工作示例 metadata: creationTimestamp: null spec: template: metadata: creationTimestamp: null labels: run: hello spec: containers: - args: - /bin/sh - -c - date; echo Hello from the Kubernetes cluster image: busybox imagePullPolicy: Always name: hello resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: OnFailure schedulerName: default-scheduler securityContext: {}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。