gpt4 book ai didi

kubernetes - 避免在 Kubernetes 中为一个 cron 执行点运行多个 cron 作业

转载 作者:行者123 更新时间:2023-12-02 12:16:58 26 4
gpt4 key购买 nike

编辑:问题解决了,这是我的错误,我只是使用了错误的 cron 设置。我假设“* 2 * * *”每天仅在 2 点运行一次,但实际上它在 2 小时后每分钟运行一次。因此 Kubernetes 的行为是正确的。

我一直在一个 cron 执行点运行多个作业。但似乎只有这些作业的运行时间很短。知道为什么会发生这种情况以及如何预防吗?我用 concurrencyPolicy: Forbid , backoffLimit: 0restartPolicy: Never .

应该每天运行一次的 cron 作业的示例,但在其计划运行时间之后运行多次:

job-1554346620                   1/1           11s        4h42m   
job-1554346680 1/1 11s 4h41m
job-1554346740 1/1 10s 4h40m

相关配置:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: job
spec:
schedule: "* 2 * * *"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
containers:
- name: job
image: job_image:latest
command: ["rake", "run_job"]
restartPolicy: Never
imagePullSecrets:
- name: regcred
backoffLimit: 0

最佳答案

在 k8s 上运行 CronJobs 最常见的问题是:
产生许多消耗所有集群资源的 Pod
设置适当的 CronJob 限制非常重要
如果您不确定自己需要什么 - 只需将此示例作为模板:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: my-first-conjob
namespace: devenv-admitriev
spec:
schedule: "*/10 * * * *" # MM HH DD MM WKD -- Minutes, Hour, Day, Month, Weekday (eg. Sun, Mon)
successfulJobsHistoryLimit: 3 # how many completed jobs should be kept
failedJobsHistoryLimit: 1 # how many failed jobs should be kept
suspend: false # Here you can suspend cronjob without deliting it
concurrencyPolicy: Forbid # Choose Forbid if you don't want concurrent executions of your Job

# The amount of time that Kubernetes can miss and still start a job.
# If Kubernetes missed too many job starts (100)
# then Kubernetes logs an error and doesn’t start any future jobs.
startingDeadlineSeconds: 300 # if a job hasn't started in this many seconds, skip
jobTemplate:
spec:
parallelism: 1 # How many pods will be instantiated at once.
completions: 1 # How many containers of the job are instantiated one after the other (sequentially) inside the pod.
backoffLimit: 3 # Maximum pod restarts in case of failure
activeDeadlineSeconds: 1800 # Limit the time for which a Job can continue to run
template:
spec:
restartPolicy: Never # If you want to restart - use OnFailure
terminationGracePeriodSeconds: 30
containers:
- name: my-first-conjob
image: busybox
command:
- /bin/sh
args:
- -c
- date; echo sleeping....; sleep 90s; echo exiting...;
resources:
requests:
memory: '128Mi'
limits:
memory: '1Gi'

关于kubernetes - 避免在 Kubernetes 中为一个 cron 执行点运行多个 cron 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55510489/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com