How to Create a Cronjob and specifying active deadline seconds

This is a Cronjob that runs every one minute and execute the command “uname” in the container. This cronjob specify an active deadline seconds of 10 which means the running command in the container has to complete in 10 seconds after the container is started.

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          activeDeadlineSeconds: 10
          containers:
          - name: hello
            image: busybox
            args:
            - /bin/sh
            - -c
            - uname;
          restartPolicy: OnFailure

segmentionError:~ babatundeolu-isa$ kubectl create -f uname.yaml
cronjob.batch "hello" created
segmentionError:~ babatundeolu-isa$ kubectl get cj
NAME      SCHEDULE      SUSPEND   ACTIVE    LAST SCHEDULE   AGE
hello     */1 * * * *   False     0                   12s
segmentionError:~ babatundeolu-isa$ kubectl get jobs
NAME               DESIRED   SUCCESSFUL   AGE
hello-1532541840   1         1            5s
segmentionError:~ babatundeolu-isa$ kubectl get pods
NAME                     READY     STATUS      RESTARTS   AGE
hello-1532541840-5hptw   0/1       Completed   0          10s

Leave a Reply

Your email address will not be published. Required fields are marked *