Job を使ってみる (kubernetes)
kubernetes
Published: 2021-01-01

やったこと

Job を使ってみます。

確認環境

$ k version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2", GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean", BuildDate:"2019-10-15T19:18:23Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:41:49Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}

調査

job.yaml

apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(20)"]
      restartPolicy: Never
  backoffLimit: 4
  parallelism: 3
  completions: 10
$ k apply -f job.yaml
job.batch/pi created
$ k get pods --watch
NAME       READY   STATUS              RESTARTS   AGE
pi-7x8sv   0/1     ContainerCreating   0          6s
pi-k6mxv   0/1     ContainerCreating   0          6s
pi-tg6cx   0/1     ContainerCreating   0          6s
pi-7x8sv   0/1     Completed           0          108s
pi-8gbgj   0/1     Pending             0          0s
pi-8gbgj   0/1     Pending             0          0s
pi-8gbgj   0/1     ContainerCreating   0          0s
pi-k6mxv   0/1     Completed           0          110s
pi-dtbll   0/1     Pending             0          0s
pi-dtbll   0/1     Pending             0          0s
pi-dtbll   0/1     ContainerCreating   0          0s
pi-tg6cx   0/1     Completed           0          119s
pi-cl6fx   0/1     Pending             0          0s
pi-cl6fx   0/1     Pending             0          0s
pi-cl6fx   0/1     ContainerCreating   0          0s
pi-8gbgj   0/1     Completed           0          17s
... (省略)

Job 終了後の結果

$ k get jobs
NAME   COMPLETIONS   DURATION   AGE
pi     10/10         2m34s      11m

参考