Setting Up Cron Jobs¶
This guide describes how to set up cron jobs for Open edX instances on the cluster using CronJob resource for custom tasks.
Kubernetes CronJob¶
For custom cron jobs:
- Define a CronJob - Create a CronJob manifest (schedule, job template, image, command). Use an image that has the required tools (e.g. openedx image or a minimal runner).
- Place in instance manifests - Add the CronJob to the instance’s manifest directory so ArgoCD syncs it.
- Secrets and config - Mount any required secrets (e.g. DB, API keys) into the CronJob’s job template so the job can connect to services.
Example (conceptual):
apiVersion: batch/v1
kind: CronJob
metadata:
name: my-custom-job
namespace: <instance-name>
spec:
schedule: "0 2 * * *" # 2 AM daily
jobTemplate:
spec:
template:
spec:
containers:
- name: job
image: <your-image>
command: ["/path/to/script.sh"]
restartPolicy: OnFailure
Deploying with ArgoCD¶
CronJobs are deployed via ArgoCD from the cluster repository. The instance’s ArgoCD Application must include the path where the CronJob manifests live, and a sync must be triggered after changes.
-
Update
application.ymlso ArgoCD also sees the cron manifests:# ... spec: project: default sources: - path: "instances/<instance-name>/env" repoURL: "git@github.com:open-craft/<cluster-repo-name>" targetRevision: "main" - path: "instances/<instance-name>/manifests" repoURL: "git@github.com:open-craft/<cluster-repo-name>" targetRevision: "main" # ... -
Add the CronJob manifest in the
manifestsdirectory. Use the instance’s namespace in the CronJobmetadata.namespace. -
Commit and push the CronJob YAML and any change to
application.ymlto the cluster repo. -
Trigger a sync for the instance’s ArgoCD Application (UI or CLI). A sync is required for the new or updated CronJobs to be applied.
-
Verify in the ArgoCD application view or with
kubectl get cronjob -n <instance-name>.
Any change to the CronJob (schedule, image, command) should be made in the manifest in the repo and committed; direct edits with kubectl will be reverted on the next ArgoCD sync.
Related Documentation¶
- User Guides Overview - All user guides
- Instance Configuration - Where manifests live
- Instances Overview - Instance lifecycle
See Also¶
- Instance Provisioning - Instance layout
- Docker Images - Custom images for cron
- Instance Debugging - Troubleshooting jobs