Batch and Cron Jobs
Batch job
apiVersion: batch/v1
kind: job
metadata:
name: batch-job
spec:
completions: 3 # The number of pods to run sequentially.
parallelism: 2 # Run up to 2 pods in parallel. Equivalent to replicas.
template:
metadata:
labels:
app: batch-job
spec:
restartPolicy: OnFailure # OnFailure, Never or Always (doesn't make sense
# to use this option for batch jobs)
containers:
- name: main
image: thomaspk/web
An example of a batch job. Once the batch job finishes, its STATUS turns to Completed
. The job is not deleted so that one can look at the application logs.
Cron job
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: cron-job
spec: # spec for the CronJob
schedule: "0,15,30,45 * * * *"
startingDeadlineSeconds: 15 # Start job within 15 seconds of scheduled time.
jobTemplate:
spec: # spec for the jobTemplate
template:
metadata:
labels:
app: periodic-job
spec: # spec for the pod
restartPolicy: OnFailure # OnFailure, Never or Always (doesn't make sense
# to use this option for batch jobs)
containers:
- name: main
image: thomaspk/web
An example of a cron job that runs every 15 minutes.