我已经创建了一个Kubernetes Scheduled Job,根据它的时间表每天运行两次。但是,出于测试目的,我希望手动触发它。我该怎么做呢?


当前回答

编辑- 2018年7月:见@pedro_sland的回答,因为这个功能现在已经实现了

对于低于v1.10.1的旧版本的kubectl,下面我的原始答案仍然正确

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

除了创造一份新工作(正如其他答案所建议的那样),目前还没有办法做到这一点。这是kubernetes的一个功能请求,可以在这里跟踪:https://github.com/kubernetes/kubernetes/issues/47538

其他回答

kubectl create job --from=cronjob/<cron-job-name> <job-name> -n <namespace>

kubectl delete job <job-name> -n <namespace>

如果您想查看可用的玉米作业列表,请使用kubectl get cronjobs -n <命名空间>

在k8s仪表板的这个选项卡中有一个手动触发cron作业的选项

编辑- 2018年7月:见@pedro_sland的回答,因为这个功能现在已经实现了

对于低于v1.10.1的旧版本的kubectl,下面我的原始答案仍然正确

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

除了创造一份新工作(正如其他答案所建议的那样),目前还没有办法做到这一点。这是kubernetes的一个功能请求,可以在这里跟踪:https://github.com/kubernetes/kubernetes/issues/47538

为了方便,我创建了一个小的cmd实用程序来挂起和取消cronjobs。

https://github.com/iJanki/kubecron

@jdf提到的#47538问题现在已经结束,现在是可能的。原始的实现可以在这里找到,但是语法已经改变了。

在kubectl v1.10.1+中,命令如下:

Kubectl create job——from=cronjob/<cronjob-name> <job-name> -n <namespace-name>

它似乎向后兼容旧的集群,因为它在v0.8.x上为我工作。