【发布时间】: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