Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes difference between activeDeadlineSeconds in Job and Pod

Tags:

kubernetes

Kubernetes provides a activeDeadlineSeconds field for both JobSpec and PodSpec

What is the difference between the two? I've put together a little job with activeDeadlineSeconds set to 20, and in its Pod definition I have set the activeDeadlineSeconds field to 45. These are kind of arbitrary but meant to be spaced out. When I create/apply the Job then run kubectl get pods -a --watch, I can see that the 20 deadline isn't having any effect but the second one is (I see the DeadlineExceeded output).

Just to be extra certain, I added terminationGracePeriodSeconds: 10 in the PodSpec and see the same thing.

What is the purpose of the activeDeadlineSeconds in the Job? It doesn't seem to be sending any signal to my container.

Note: I'm simply running the sleep command on an ubuntu image. This command should exit when receiving the TERM signal sent by Kubernetes (so I expect a TERM signal at 20 seconds then the pod to die shortly thereafter)

Condensed YAML definition:

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']

References:

  • https://v1-7.docs.kubernetes.io/docs/api-reference/v1.7/#jobspec-v1-batch
  • https://v1-7.docs.kubernetes.io/docs/api-reference/v1.7/#podspec-v1-core
  • https://unix.stackexchange.com/questions/429594/why-sigterm-is-able-to-kill-sleep
like image 991
s g Avatar asked Nov 27 '18 18:11

s g


People also ask

What is the difference between POD and job in Kubernetes?

Pod is basic unit to express a runnable process on Kubernetes. Job is a higher level abstraction that uses pods to run a completable task. You might be thinking of using a pod with restartPolicy: Never to run a completable task.

What is difference between job and deployment in Kubernetes?

simply put: deployments are used for services that are expected to be up and running continuously. think webservers, databases, etc. jobs/cronjobs are meant for tasks that are meant to be run and exit after they have finished. think: database backups, etcs.

What is activeDeadlineSeconds?

The activeDeadlineSeconds value is relative to the startTime of the Job, and applies to the duration of the Job, no matter how many Pods are created. To specify a deadline, add the activeDeadlineSeconds value to the Job's spec field in the manifest file.


1 Answers

Community wiki answer for future:

As per @Clorichel this issue was fixed in k8s v1.8 https://github.com/kubernetes/kubernetes/issues/32149

My advice is to upgrade your cluster to the latest version, if is possible to have access to newest features and bug fixes.

like image 176
Vit Avatar answered Oct 23 '22 03:10

Vit