问题描述
我必须在Kubernetes中部署 Cronjob ,这将每15分钟创建一个Job Pod.作业将检查服务是否准备好提供新数据.准备好此服务后,该作业将需要1个多小时才能完成其执行.问题围绕这样一个事实,即将在此期间执行其他作业.
I have to deploy a Cronjob in Kubernetes that will create a Job pod every 15 minutes. The job will check if a service is ready to provide new data. Once this service is ready, the job will take more than 1 hour to complete its execution. The problem revolves around the fact that other jobs are going to be executed during this time.
简而言之,当已有作业正在运行时,如何防止在 Kubernetes Cronjobs 中执行作业?
In short, how can I prevent a job to be executed in Kubernetes Cronjobs when there's already a Job running?
推荐答案
CronJob资源具有一个名为concurrencyPolicy
的属性,此处为示例:
CronJob resource has a property called concurrencyPolicy
, here an example:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: your-cron
spec:
schedule: "*/40 8-18 * * 1-6"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
metadata:
labels:
app: your-periodic-job
spec:
containers:
- name: your_container
image: your_image
imagePullPolicy: IfNotPresent
restartPolicy: OnFailure
这篇关于如果已有作业正在运行,如何防止在Kubernetes中执行Cronjob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!