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.
- k9.batch.list_cron_jobs(namespace: Optional[str] = None)[source]¶
List all cluster cron jobs :param namespace: Then namespace to list cron jobs from. If None, uses the default namespace. :return: A list of dictionary items with name and created.
- k9.batch.create_cron_job(body: dict, namespace: Optional[str] = None)[source]¶
Create a cron job
- Parameters
body – The cron job definition object.
namespace – Then namespace to create cronjob in. If None, uses the default namespace.
- Returns
- k9.batch.delete_cron_job(name: str, namespace: Optional[str] = None)[source]¶
Deletes the specified cron job
- Parameters
name – Name of cron job
namespace – Then namespace to delete cron job from. If None, uses the default namespace.
- Returns
None if cron job doesn’t exist, V1Status