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:
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With