Re-run A Kubernetes Scheduled Job manually

A Kubernetes Scheduled Job is designed to run automatically based on a schedule defined in the cron format. However, there are a few ways to trigger a Scheduled Job manually.

Edit the schedule

You can edit the schedule in the Job’s YAML file and set it to run immediately. Once you have made the change, you can apply it by running the kubectl apply -f command.

Run a one-time Job

You can create a one-time Job that runs the same container as the Scheduled Job. Once the Job completes, it will not be rescheduled.

reate a Job config from your Cron Job (ScheduledJob) config and run it manually using the following command:

kubectl create -f ./job.yaml
Delete and recreate the Job

You can delete the existing Scheduled Job by running kubectl delete job and then recreate it by running kubectl create -f .

kubectl create -f ./job.yaml
Using kubectl command

You can use kubectl command and create a Job with the same configuration as the scheduled job and use –from flag to reference the scheduled job.

kubectl create job --from=cronjob/<scheduled-job-name>

Please note that, depending on the job configuration, you may also need to manually clean up completed pods and/or jobs created by the scheduled job.

It is important to keep in mind that modifying the schedule of a job that is running in production may have an impact on the system and it should be done carefully and with a proper testing and validation.

Leave a Reply

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