首页 > 解决方案 > Kubernetes CronJob 创建的已完成 pod 在一段时间后被删除

问题描述

我使用下面的 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(完成后)会在一段时间后被删除。

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

标签: kuberneteskubernetes-jobs

解决方案


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

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


推荐阅读