24
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2018-09-06

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

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

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

Options:
      --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:
json|yaml|name|go-template-file|templatefile|template|go-template|jsonpath-file|jsonpath.
      --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 [http://golang.org/pkg/text/template/#pkg-overview].
      --validate=true: If true, use a schema to validate the input before sending it

Usage:
  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
24
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?