.. _cron_job:
Cron Job
--------
A `Cron Job `_ creates jobs that run on a specific
timed interval. You'll want to create a YAML file describing the cron job::
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: xx-ecr-login-cron
spec:
schedule: "* */8 * * *"
successfulJobsHistoryLimit: 2
failedJobsHistoryLimit: 2
concurrencyPolicy: Forbid
jobTemplate:
spec:
backoffLimit: 4
template:
spec:
serviceAccountName: ecr-cron-sa
terminationGracePeriodSeconds: 0
restartPolicy: Never
containers:
- name: ecr-login
imagePullPolicy: Always
image: simoncomputing/ecr-login:1.0
command:
- "/login.sh"
env:
- name: ECR_URL
valueFrom:
secretKeyRef:
name: aws-info
key: ecr-url
- name: AWS_ACCOUNT
valueFrom:
secretKeyRef:
name: aws-info
key: aws-account
- name: AWS_REGION
valueFrom:
secretKeyRef:
name: aws-info
key: region
- name: NAMESPACES
value: "default"
This is an example of running a cron job that will create a container to run from a predefined
Docker image.
The **schedule** is in a standard `Cron `_ format.
Note that you wil also want to run it with a service account that you've created with the appropriate
permissions.
.. autofunction:: k9.batch.list_cron_jobs
.. autofunction:: k9.batch.create_cron_job
.. autofunction:: k9.batch.delete_cron_job
.. autofunction:: k9.batch.get_cron_job
.. autofunction:: k9.batch.cron_job_exists