How to change the schedule of a Kubernetes cronjob or how to start it manually?

The more recent versions of k8s (from 1.10 on) support the following command:

$ kubectl create job my-one-time-job --from=cronjobs/my-cronjob

Source is this solved k8s github issue.


You can update only the selected field of resourse by patching it

patch -h                     
Update field(s) of a resource using strategic merge patch, a JSON merge patch, or a JSON patch.           

JSON and YAML formats are accepted.

Please refer to the models in
https://htmlpreview.github.io/?https://github.com/kubernetes/kubernetes/blob/HEAD/docs/api-reference/v1/definitions.html
to find if a field is mutable.

As provided in comment for ref :

kubectl patch cronjob my-cronjob -p '{"spec":{"schedule": "42 11 * * *"}}'

Also, in current kubectl versions, to launch a onetime execution of a declared cronjob, you can manualy create a job that adheres to the cronjob spec with

kubectl create job --from=cronjob/mycron