0
0

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の更新

0
Posted at

はじめに

KubernetesのCronJobの更新を実施した際の動きについてのメモです。

結論

Jobが起動している状態で、新しいイメージを指定してCronJobを更新した場合、既存のJobが削除されることはない。
CronJob自体を削除すると、Jobも削除される。

確認

CronJobを作成します。

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            args:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster; sleep 600
          restartPolicy: OnFailure
$ k apply -f cronjob.yaml                                                                                
cronjob.batch/hello created

Jobの起動確認

$ k get job
NAME               COMPLETIONS   DURATION   AGE
hello-1599204120   0/1           5s         5s

コンテナイメージの変更
image: busybox ->image: busybox:uclibc

$ k apply -f cronjob.yaml
cronjob.batch/hello configured

古いバージョンのJobが起動していることを確認

$ k get job
NAME               COMPLETIONS   DURATION   AGE
hello-1599204120   0/1           81s        81s
hello-1599204180   0/1           21s        21s
$ k get job hello-1599204120 -o yaml | grep image
       image: busybox
$ k get job hello-1599204180 -o yaml | grep image
       image: busybox:uclibc

CronJobを削除してみる

$ k get job
NAME               COMPLETIONS   DURATION   AGE
hello-1599204120   0/1           9m56s      9m56s
hello-1599204180   0/1           8m56s      8m56s
hello-1599204240   0/1           7m56s      7m56s
hello-1599204300   0/1           6m56s      6m56s
hello-1599204360   0/1           5m56s      5m56s
hello-1599204420   0/1           4m56s      4m56s
hello-1599204480   0/1           3m56s      3m56s
hello-1599204540   0/1           2m55s      2m55s
hello-1599204600   0/1           115s       115s
hello-1599204660   0/1           55s        55s
$ k delete -f cronjob.yaml
cronjob.batch "hello" deleted
atsum@cs-660110948249-default-default-689gh:~/knative$ k get job
No resources found in default namespace.
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?