How can I run a scheduled Kubernetes task manually?

I created Kubernetes Scheduled Task , which runs twice a day according to its schedule. However, I would like to run it manually for testing. How can i do this?

+75
source share
6 answers

Problem # 47538 that @jdf mentioned is now closed, and now it is possible. The original implementation can be found here , but the syntax has changed.

In kubectl v1.10. 1+ command looks like this:

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

It seems to be backward compatible with old clusters since it worked for me on v0.8.x.

+120
source

You can create a simple job based on your ScheduledJob. If you already run ScheduledJob, there are tasks in the story.

 kubectl get jobs NAME DESIRED SUCCESSFUL AGE hello-1477281595 1 1 11m hello-1553106750 1 1 12m hello-1553237822 1 1 9m 

Export one of these jobs:

 kubectl get job hello-1477281595 -o yaml > my_job.yaml 

Then modify yaml a bit by deleting the unnecessary fields and starting them manually:

 kubectl create -f my_job.yaml kubectl delete -f my_job.yaml 
+13
source

UPDATE - July 2018: see @Pedro_sland answer for this feature is now implemented

My original answer below will remain true for older versions of kubectl less than v1.10.1

=================================================== ========================

Other than creating a new job (as other answers suggested), there is currently no way to do this. This is a function request in kubernetes now, which can be tracked here: https://github.com/kubernetes/kubernetes/issues/47538

+9
source

Unfortunately, none of the above syntax examples work in the Google Kubernetes Engine (GCP). Also, the GKE documents themselves are incorrect. :(

In Kubernetes 1.10.6.gke-2 working syntax is:

 kubectl create job <your-new-job-name> --from=cronjob/<name-of-deployed-cron-job> -n <target namespace> 
+4
source

I created a small cmd utility for the convenience of doing this, as well as pausing and disabling cronjobs.

https://github.com/iJanki/kubecron

+3
source

If you want to test the job, create a Job config from Cron Job (ScheduledJob) and run it manually using the following command:

 kubectl create -f ./job.yaml 
+1
source

Source: https://habr.com/ru/post/1259219/


All Articles