mingming

kubernetes controller - CronJob 본문

kubernetes

kubernetes controller - CronJob

mingming_96 2023. 9. 5. 17:32

CronJob

Job controller로 실행할 Application Pod를 주기적으로 반복해서 실행 

Linux의 cronjob 스케쥴링 기능을 Job Controller에 추가한 API 

다음과 같은 반복해서 실행하는 Job을 운영해야 할 때 사용 

  Data Backup

  Send email

  Cleaning tasks

 

Cronjob Schedule:

  Minutes (from 0 to 59 )

  Hours ( from 0 to 23 )

  Day of the month ( from 1 to 31 )

  Month ( fron 1 to 12 ) 

  Day of the week ( from 0 to 6 )

 

Job vs CronJob Definition 

 

Job Definition 

apiVersion: batch/v1
kind: Job
metadata:
  name: centos-job
spec:
  template:
    spec:
      containers:
      - name: centos-container
        image: centos:7
        command: ["bash"]
        args:
        - "-c"
        - "echo 'Hello'; sleep 5; echo "Bye"
      restarPolicy: Never

 

CronJob Definition

apiVersion: batch/v1
kind: Job
metadata:
  name: centos-job
spec:
  schedule: "0 3 1 * *"
  jobTemplate:
    spec:
      containers:
      - name: centos-container
        image: centos:7
        command: ["bash"]
        args:
        - "-c"
        - "echo 'Hello'; sleep 5; echo "Bye"
      restarPolicy: Never

 

CronJob.yaml

apiVersion: batch/v1
kind: CronJob
metadata:
  name: cronjob-exam
spec:
  schedule: "* * * * *"
  startingDeadlineSeconds: 300
  concurrencyPolicy: Forbid
  jobTemplate
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            args:
            - /bin/sh
            - -c
            - echo Hello; sleep 80; echo Bye
          restartPolicy: Never

concurrencyPolicy: Allow 작업이 실행중이여도 실행

concurrencyPolicy: Forbid  작업이 실행중이면 동작시키지 않음 

startingDeadlineSeconds: 일정 시간동안 해당 job을 실행시키지 못한다면 작업을 종료

 

'kubernetes' 카테고리의 다른 글

Prometheus on kubernetes  (0) 2023.09.18
Kubernetes Monitoring 시스템 ( Prometheus & Grafana )  (0) 2023.09.17
kubernetes controller - Job  (0) 2023.09.05
kubernetes controller - StatefulSet  (0) 2023.09.04
kubernetes controller - Deployment  (1) 2023.09.04