Kubernetes Job 和 Pod 中 activeDeadlineSeconds 的区别

s g*_*s g 9 kubernetes

Kubernetes提供了一个activeDeadlineSeconds领域都JobSpecPodSpec

两者有什么区别?我整理了一个activeDeadlineSeconds设置为 20的小工作,在它的 Pod 定义中,我将activeDeadlineSeconds字段设置为 45。这些有点随意,但意味着要间隔开。当我创建/应用 Job 然后运行时kubectl get pods -a --watch,我可以看到 20 截止日期没有任何影响,但第二个截止日期是(我看到DeadlineExceeded输出)。

为了更加确定,我添加terminationGracePeriodSeconds: 10了 PodSpec 并看到了同样的事情。

activeDeadlineSeconds在工作中的目的是什么?它似乎没有向我的容器发送任何信号。

注意:我只是sleepubuntu图像上运行命令。当接收到 Kubernetes 发送的 TERM 信号时,这个命令应该退出(所以我希望在 20 秒时有一个 TERM 信号,然后 pod 会在此后不久死亡)

简明的 YAML 定义:

apiVersion: batch/v2alpha1  # K8s 1.7.x
kind: CronJob
spec:
  schedule: "*/1 * * * *"
  concurrencyPolicy: Allow
  jobTemplate:
    spec:  # JobSpec
      activeDeadlineSeconds: 20   # This needs to be shorter than the cron interval  ## TODO - NOT WORKING!
      parallelism: 1
      template:  # PodTemplateSpec
        spec:
          activeDeadlineSeconds: 45
          terminationGracePeriodSeconds: 10
          containers:
          - name: ubuntu-container
            image: ubuntu
            command: ['bash', '-c', 'sleep 500000']
Run Code Online (Sandbox Code Playgroud)

参考:

Vit*_*Vit 3

社区维基未来的答案:

根据@Clorichel,这个问题已在 k8s v1.8 中修复 https://github.com/kubernetes/kubernetes/issues/32149

我的建议是将集群升级到最新版本,如果可以的话,可以访问最新的功能和错误修复。