k8s cronjob设置作业失败后退出不重复执行

Optional parameters

backoffLimit: Number of retries for pods launched by the job. If you want your pods to never restart, you need to set it at 0. However due to some issuewhere pod can’t be restarted beyond backoffLimit it’s better, if you use restartPolicy : Never”.

 

Here is a more detailed cronjob example with most of the parameters:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: test
spec:
  schedule: "30 16,17,18,19 * * *"
  concurrencyPolicy: "Forbid"
  failedJobsHistoryLimit: 10
  startingDeadlineSeconds: 600 # 10 min
  jobTemplate:
    spec:
      backoffLimit: 0
      activeDeadlineSeconds: 3300 # 55min
      template:
        spec:
          containers:
            - name: hello
              image: python:3.6-slim
              command: ["python"]
              args: ["/usr/src/app/job_offers.py"]
          restartPolicy: Never

  

实例配置:

kubectl get  cronjob  job-2528049150-app-v1-0   -n data-infra -o yaml
**********
spec:
  concurrencyPolicy: Allow
  failedJobsHistoryLimit: 10
  jobTemplate:
    metadata:
      annotations:
        helm.sh/namespace: data-infra
        helm.sh/path: app
        helm.sh/release: job-2528049150
      creationTimestamp: null
      labels:
        controller.caicloud.io/chart: app
        controller.caicloud.io/release: job-2528049150
    spec:
      activeDeadlineSeconds: 36000
      backoffLimit: 0
      completions: 1
      parallelism: 1
      template:
        metadata:
          annotations:
            helm.sh/namespace: data-infra
            helm.sh/path: app
            helm.sh/release: job-2528049150
          creationTimestamp: null
          labels:
            controller.caicloud.io/chart: app
            controller.caicloud.io/name: job-2528049150-app-v1-0
            controller.caicloud.io/release: job-2528049150
        spec:
          containers:
          - command:
            - python
            - -m
            - fashion_bi.FbMainServer
            env:
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
            - name: POD_IP
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: status.podIP
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: spec.nodeName
            - name: SERVING_TYPE
              value: ins
            image: cargo.caicloudprivatetest.com/data-infra_pro/fb_main_server:3.7
            imagePullPolicy: Always
            name: c0
            resources:
              limits:
                cpu: "2"
                memory: 4Gi
              requests:
                cpu: 250m
                memory: 512Mi
            securityContext:
              privileged: false
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: Never
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
  schedule: 00 21 * * *
  successfulJobsHistoryLimit: 10
  suspend: false
status:
  lastScheduleTime: 2019-04-25T21:00:00Z

  

转载于:https://www.cnblogs.com/weifeng1463/p/10773375.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值