【问题标题】:Finished pods created by Kubernetes CronJob getting deleted after sometimeKubernetes CronJob 创建的已完成 pod 在一段时间后被删除
【发布时间】:2020-03-11 19:44:00
【问题描述】:

我使用下面的 yaml 文件创建了一个 CronJob。

kind: CronJob
metadata:
  name: $DEPLOY_NAME
spec:
  # Run the job once a day at 8 PM
  schedule: "0 20 * * *"
  # If the previous job is not yet complete during the scheduled time, do not start the next job
  concurrencyPolicy: Forbid
  jobTemplate:
      spec:
        # The pods will be available for 3 days (259200 seconds) so that logs can be checked in case of any failures
        ttlSecondsAfterFinished: 259200
        template:
          spec:
            containers:
            - name: $DEPLOY_NAME
              image: giantswarm/tiny-tools
              imagePullPolicy: IfNotPresent
              resources:
                requests:
                  cpu: "0.01"
                  memory: 256Mi
                limits:
                  cpu: "0.5"
                  memory: 512Mi
              command: ["/bin/sh"]
              args: ["-c", "cd /home/tapi && sh entrypoint.sh"]

正如ttlSecondsAfterFinished 中提到的,k8s 将我的工作保留在集群中。但是,作业创建的 pod(完成后)会在一段时间后被删除。

根据garbage collection policy,我的 pod 对象应该取决于我的工作。而且由于作业对象没有被垃圾收集,我的 pod 对象也应该保持活动状态。我错过了什么吗?

【问题讨论】:

  • 一些时间有多长?
  • 不太确定。 2-3小时即可。这项工作在晚上执行。早上,当我们尝试从 pod 获取日志时,pod 本身不可用。我们尝试在白天安排作业,当时 pod 至少保留 2 小时。
  • kubectl describe cronjob $DEPLOY_NAME 并检查Events
  • 检查 Kubernetes 版本 - 通过设置 .spec.ttlSecondsAfterFinished 完成作业的 TTL 在 v1.12 中引入。如果版本是 v1.12+ 则检查功能门TTLAfterFinished 是否已启用。
  • 对我来说,事件是空的

标签: kubernetes kubernetes-jobs


【解决方案1】:

.spec.successfulJobsHistoryLimit 和 .spec.failedJobsHistoryLimit 字段是可选的。 这些字段指定应保留多少已完成和失败的作业。 默认情况下,它们分别设置为 3 和 1。

您可能需要将这些字段设置为适当的值

【讨论】:

  • 虽然,当我查看kubectl get jobs 时,我只看到 3 个工作。但是,如果我检查`kubectl describe cronjob abc`,failjobhistortlimit 将变为 1。但成功限制将与 824638391724 一样高
  • 您需要描述已完成的工作
  • 我也这样做了。但其中没有任何事件。请告诉我我还应该检查什么。在工作中,。没有定义成功和失败的限制。
猜你喜欢
  • 2017-05-14
  • 1970-01-01
  • 2022-12-11
  • 1970-01-01
  • 1970-01-01
  • 2019-07-31
  • 2017-04-02
  • 2021-12-15
  • 2021-06-20
相关资源
最近更新 更多