k8s cronjob

发布时间 2023-11-09 09:43:43作者: lixinliang

k8s cronjob 任务模版

  • k8s cronjob 任务模版
cat > ${k8s_resource_list}-cronjob.yaml << EOF
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: ${k8s_resource_list}
  namespace: ${namespace}
spec:
  schedule: "*/1 * * * *"  
  startingDeadlineSeconds: 300 
  concurrencyPolicy: Forbid  
  suspend: false  
  jobTemplate:
    spec:
      parallelism: 2 #同时执行的pod 数量,即副本数量
      backoffLimit: 4 # 最大允许失败的次数
      template:
        spec:
          restartPolicy: OnFailure
          volumes:
            - name: storage
              hostPath:
                path: /applogs/project/volume-${namespace}/${k8s_resource_list}
                type: ""
            - name: volume-localtime
              hostPath:
                path: /etc/localtime
          containers:
            - name: ${k8s_resource_list}
              image: ${mirror_store}/${image_name}:${BUILD_TIMESTAMP}
              volumeMounts:
                - name: volume-localtime
                  mountPath: /etc/localtime
                - name: storage
                  mountPath: /export/home/webroot/${namespace}/extend/logs 
EOF