본문 바로가기

클라우드/쿠버네티스(Kubernetes)

쿠버네티스 Kubernetes 크론잡 (CronJob)

batch

같은 그룹이더라도 다른 버전을 사용할 수 있다

동시실행정책

끝나는 시간이 정해져있다

 

60ㅊ 간격으로 80초동안 실행?

동시에동시 두개의 작업이 실행

allow 기본값 실행

forbid

replace 기존에있던걸 취소

백ㅇㅓㅂ작업이며 ㄴ 단일백업이 보장 ->forbid

vagrant@k-control:~$ kubectl create -f ldh-cj.yml
error: error parsing ldh-cj.yml: error converting YAML to JSON: yaml: line 19: found unexpected end of stream
vagrant@k-control:~$ vi ldh-cj.yml
vagrant@k-control:~$ kubectl create -f ldh-cj.yml
error: error validating "ldh-cj.yml": error validating data: ValidationError(CronJob.spec.jobTemplate.spec): unknown field "spec" in io.k8s.api.batch.v1.JobSpec; if you choose to ignore these errors, turn validation off with --validate=false
vagrant@k-control:~$ vi ldh-cj.yml
vagrant@k-control:~$ vi ldh-cj.yml
vagrant@k-control:~$ kubectl create -f ldh-cj.yml
The CronJob "ldh-cj" is invalid: 
* spec.jobTemplate.spec.template.spec.restartPolicy: Unsupported value: "Onfailure": supported values: "Always", "OnFailure", "Never"
* spec.jobTemplate.spec.template.spec.restartPolicy: Unsupported value: "Onfailure": supported values: "OnFailure", "Never"
vagrant@k-control:~$ vi ldh-cj.yml
vagrant@k-control:~$ kubectl create -f ldh-cj.yml
cronjob.batch/ldh-cj created
vagrant@k-control:~$ kubectl get cronjobs.batch
NAME     SCHEDULE      SUSPEND   ACTIVE   LAST SCHEDULE   AGE
ldh-cj   */2 * * * *   False     1        60s             5m41s
vagrant@k-control:~$ kubectl get pods --watch
NAME                      READY   STATUS             RESTARTS   AGE
h                         0/1     ImagePullBackOff   0          17m
ldh-cj-1625807880-9jmkk   0/1     Completed          0          5m24s
ldh-cj-1625808000-rpmhh   0/1     Completed          0          3m23s
ldh-cj-1625808120-swvdl   0/1     Completed          0          93s
ldh-rs-2dkt8              1/1     Running            0          73m
ldh-rs-52kqm              1/1     Running            0          73m
ldh-rs-9m5k4              1/1     Running            0          66m
ldh-rs-f4sqr              1/1     Running            0          73m
ldh-rs-vjp5n              1/1     Running            0          66m
^Cvagrant@k-control:~$ kubectl get cronjobs.batch
NAME     SCHEDULE      SUSPEND   ACTIVE   LAST SCHEDULE   AGE
ldh-cj   */2 * * * *   False     0        110s            6m31s
vagrant@k-control:~$ kubectl delete -f ldh-cj.yml
cronjob.batch "ldh-cj" deleted
vagrant@k-control:~$ cat ldh.cj.yml
cat: ldh.cj.yml: No such file or directory
vagrant@k-control:~$ cat ldh-cj.yml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: ldh-cj
spec:
  schedule: "*/2 * * * *"
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            app: ldh-cj
        spec:
          restartPolicy: OnFailure
          containers:
          - name: ldh
            image: busybox
            command: ["sleep", "60"]