简体   繁体   English

Kubernetes使用CronJob运行作业

[英]Kubernetes Run job using CronJob

Is there a way through which I can run an existing Job using CronJob resource. 有没有一种方法可以使用CronJob资源运行现有的Job。 In CronJob Spec template can we apply a selector using labels. 在CronJob Spec模板中,我们可以使用标签应用选择器。 Something like this: 像这样:

Job Spec: ( Link to job docs ) 职位规格:( 链接到职位文档

apiVersion: batch/v1
kind: Job
label:
  name: pi
spec:
  template:
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
  backoffLimit: 4

Cron Spec: Cron规格:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: pi-cron
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      labelSelector:
        name: pi # refer to the job created above

I came across this. 我碰到了这个。 I want to try inverse of this. 我想尝试与此相反。 Create-Job-From-Cronjob 创建-工作-从-的cronjob

No, you can not do this in the way you want. 不,您无法按照自己的方式进行操作。 kubectl only allows you to create jobs based on cronjob, but not vise-versa. kubectl仅允许您基于cronjob创建作业,反之亦然。

 kubectl create job NAME [--image=image --from=cronjob/name] -- [COMMAND] [args...] [flags] [options]

Available commands right now for kubectl create: 现在可用于kubectl create的命令:

  clusterrole         Create a ClusterRole.
  clusterrolebinding  Create a ClusterRoleBinding for a particular ClusterRole
  configmap           Create a configmap from a local file, directory or literal value
  deployment          Create a deployment with the specified name.
  job                 Create a job with the specified name.
  namespace           Create a namespace with the specified name
  poddisruptionbudget Create a pod disruption budget with the specified name.
  priorityclass       Create a priorityclass with the specified name.
  quota               Create a quota with the specified name.
  role                Create a role with single rule.
  rolebinding         Create a RoleBinding for a particular Role or ClusterRole
  secret              Create a secret using specified subcommand
  service             Create a service using specified subcommand.
  serviceaccount      Create a service account with the specified name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM