Help us understand the problem. What is going on with this article?

CronJob をその場で Job を作って実行する方法

More than 1 year has passed since last update.

CronJob を書いた時に、一回実行したいときや、また CronJob で失敗したときなどで、もう一回実行したい時がたまにある。
その時に、わざわざ kind: Job を作らずに、 Cronjob を指定して Job を作成することができる。

  • kubectl create job -h
$ kubectl create job -h
Create a job with the specified name.

  # Create a job from a CronJob named "a-cronjob"
  kubectl create job test-job --from=cronjob/a-cronjob

      --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in
the template. Only applies to golang and jsonpath output formats.
      --dry-run=false: If true, only print the object that would be sent, without sending it.
      --from='': The name of the resource to create a Job from (only cronjob is supported).
  -o, --output='': Output format. One of:
      --save-config=false: If true, the configuration of current object will be saved in its annotation. Otherwise, the
annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
      --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The
template format is golang templates [].
      --validate=true: If true, use a schema to validate the input before sending it

  kubectl create job NAME [--from=CRONJOB] [flags] [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).

help にある以下を使うことで実現できる。

      --from='': The name of the resource to create a Job from (only cronjob is supported).
  • 実行方法
$ kubectl create job <任意の名前> --from=cronjob/<CronJob の名前> -n <ネームスペース>
  • 実行例
$ kubectl create job backup-db-2018-09-06 --from=cronjob/backup-db -n koudaiii
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away