Triggering Kubernetes Cron Jobs Manually

Kubernetes offers Cron Jobs for scheduling tasks. Sometimes, you need to run these jobs outside their scheduled times. Here's how to do it.

Listing All Cron Jobs

First, find out the available Cron Jobs:

kubectl get cronjob

This shows all Cron Jobs in the current namespace.

Triggering a Cron Job Manually

Say you have a Cron Job named daily-report. To run it manually:

kubectl create job --from=cronjob/daily-report daily-report-manual-001

This creates a new job, daily-report-manual-001, using the daily-report Cron Job setup.

Viewing Job Logs

After creating the job, you might want to check its logs:

kubectl logs -f job/daily-report-manual-001

This command shows the logs for daily-report-manual-001