Kubernetes CronJob - Notification, RunId & Logs

10/21/2019

I have a CronJob in Kubernetes which is writing logs to console and to a file. Now, I am writing a web application on top this. This application will show all the Jobs and the history of run and logs for each run.

  1. Is it possible to get logs from kubernetes for each CronJob run?
  2. Is it possible to have a side car for CronJob like normal containers?
  3. How to get CronJob notification on Job start, Job completion and Job failure?
  4. Does kubernetes generate unique JobId for each run?
  5. Is it possible to have a CronJob with future start time?
-- user1578872
kubernetes

1 Answer

10/21/2019
  1. Yes, these will be stored in the container logs on the physical node that was responsible for running the job. Additionally, the pod details/state will be retained inside of Kubernetes based on the jobs retention:

https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#clean-up-finished-jobs-automatically

  1. Yes, jobs use the standard spec.Pod specification. Meaning you can have multiple containers running inside of a single pod (ran by the job)

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#jobspec-v1-batch https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#podtemplatespec-v1-core

  1. What do we mean by this? The Kube API is the best way, you can check for the job being triggered and check the status of this job. This typically provides the status of a job:
  status:
    completionTime: "2019-10-21T02:13:16Z"
    conditions:
    - lastProbeTime: "2019-10-21T02:13:16Z"
      lastTransitionTime: "2019-10-21T02:13:16Z"
      status: "True"
      type: Complete
    startTime: "2019-10-21T01:00:08Z"
    succeeded: 1
  1. Yes, in the same way pods are given unique identifiers, when a cronjob is triggered a job with a unique identifier is created:
user:~$ kubectl get jobs -n elasticsearch
NAME                                                   COMPLETIONS   DURATION   AGE
elasticsearch-elastic-stack-kibana-backup-1571443200   1/1           5s         2d4h
elasticsearch-elastic-stack-kibana-backup-1571529600   1/1           5s         28h
elasticsearch-elastic-stack-kibana-backup-1571616000   1/1           5s         4h58m
-- Dandy
Source: StackOverflow