gpt4 book ai didi

kubernetes - 防止两个作业在Kubernetes中并行运行

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

ATT :我不知道为什么,但是有时一个 pods 突然将状态更改为“未知”,这就是新 pods 的开始位置
我在gcloud中使用kubernetes。
我为需要运行的cron作业构建了yaml文件:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: etl-table-feed-from-schema-vtex-to-schema-sale-all
spec:
schedule: "* * * * *"
concurrencyPolicy: "Forbid"
failedJobsHistoryLimit: 3
successfulJobsHistoryLimit: 1
startingDeadlineSeconds: 60 # 1 min
jobTemplate:
spec:
backoffLimit: 0
#activeDeadlineSeconds: 3600 # 1 hora
template:
spec:
containers:
- name: etl-table-feed-from-schema-vtex-to-schema-sale-all
image: (myimage)
command: ["/bin/sh", "-c"]
args: (mycommands)
env:
- name: PYTHONUNBUFFERED
value: "1"
envFrom:
- secretRef:
name: etl-secret
restartPolicy: Never
nodeSelector:
#<labelname>:value
etlnode: etl-hi-cpu
我一次只需要运行一个 pods 就可以了。但是有时候,我不知道为什么,而且我无法复制,一次运行多个 pods 。
我已经将concurrencyPolicy写为Forbid,但似乎还不够。
我在gcloud的抢占式池中运行它。
同时运行的两个Pod:
enter image description here enter image description here

最佳答案

在我的情况下,问题是concurrencyPolicy: "Forbid"activeDeadlineSeconds不够。我以前的Pod收到了SIGTERM,但在被杀死之前又继续运行了30秒,所以我最终并行运行了两个作业30秒。
看到这个问题:Kubernetes Cron Job Terminate Pod before creation of next schedule,对于我来说,此答案提供了解决方案:https://stackoverflow.com/a/63721120/5868044。两种选择:

  • 使Pod立即停在SIGTERM上(例如,使用bash trap 'exit' SIGTERM)
  • 通过设置比计划时间间隔小的activeDeadlineSeconds,可以在作业之间留出30秒以上的时间。
  • 关于kubernetes - 防止两个作业在Kubernetes中并行运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62556697/

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