gpt4 book ai didi

amazon-web-services - 在k8s中每分钟运行一次cronjob不起作用

转载 作者:行者123 更新时间:2023-12-02 11:53:50 25 4
gpt4 key购买 nike


SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
hello * * * * * False 2 2m42s 5m6s
hello * * * * * False 3 6s 5m30s
hello * * * * * False 4 6s 6m30s
hello * * * * * False 3 46s 7m10s
hello * * * * * False 1 56s 7m20s
hello * * * * * False 2 6s 7m30s
hello * * * * * False 0 26s 7m50s
hello * * * * * False 1 7s 8m31s
hello * * * * * False 0 16s 8m40s
hello * * * * * False 1 7s 9m31s
hello * * * * * False 0 17s 9m41s
hello * * * * * False 1 7s 10m



Im runnig K8S cronjob和Im使用以下命令进行观看
kubectl get cronjobs --watch -n ns1
当观看输出Im时,注意每一分钟有两个工作

例如参见 2m1s2m11s等等 …

为什么呢?我想每分钟精确地运行一次,该怎么办?
hello   * * * * *   False     0        <none>          4s
hello * * * * * False 1 7s 61s
hello * * * * * False 0 17s 71s
hello * * * * * False 1 7s 2m1s
hello * * * * * False 0 17s 2m11s
hello * * * * * False 1 7s 3m1s
hello * * * * * False 0 17s 3m11s

这是docker文件
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
namespace: monitoring
spec:
schedule: "* * * * *" # run every minute
startingDeadlineSeconds: 10 # if a job hasn't starting in this many seconds, skip
concurrencyPolicy: Forbid # either allow|forbid|replace
successfulJobsHistoryLimit: 3 # how many completed jobs should be
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure

我也尝试更改 "*/1 * * * *”之类的时间表,这没有帮助。

更新

似乎每个cronjob都有这样的条目
NAME    SCHEDULE      SUSPEND   ACTIVE   LAST SCHEDULE   AGE
hello */1 * * * * False 1 0s 7s

10秒钟后,我看到
hello              */1 * * * *                 False              0              1 0s           17s

依此类推... 一个活跃,第二个不

最佳答案

我认为您在看错东西。

CronJob 正在生成Job,因此您应该查看作业日志:

$ kubectl get jobs
NAME DESIRED SUCCESSFUL AGE
hello-1558019160 1 1 2m
hello-1558019220 1 1 1m
hello-1558019280 1 1 14s

如您所见,每分钟仅产生
concurrencyPolicy 开始播放时,可能需要较长的时间才能完成这项工作:

The .spec.concurrencyPolicy field is also optional. It specifies how to treat concurrent executions of a job that is created by this cron job. The spec may specify only one of the following concurrency policies:

  • Allow (default): The cron job allows concurrently running jobs
  • Forbid: The cron job does not allow concurrent runs; if it is time for a new job run and the previous job run hasn’t finished yet, the cron job skips the new job run
  • Replace: If it is time for a new job run and the previous job run hasn’t finished yet, the cron job replaces the currently running job run with a new job run

Note that concurrency policy only applies to the jobs created by the same cron job. If there are multiple cron jobs, their respective jobs are always allowed to run concurrently.



您还可以执行 kubectl describe jobs hello-1558019160来查看事件:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 2m job-controller Created pod: hello-1558019160-fld74

我正在运行您的 .yaml,但没有看到 Active作业高于 1

希望这可以帮助。

关于amazon-web-services - 在k8s中每分钟运行一次cronjob不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56170494/

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