mingming

kubernetes controller - Job 본문

kubernetes

kubernetes controller - Job

mingming_96 2023. 9. 5. 17:10

Job

- kubernetes는 Pod를 running 중인 상태로 유지 

- Batch 처리하는 Pod는 작업이 완료되면 종료됨

- Batch 처리에 적합한 컨트롤러로 Pod의 성공적인 완료를 보장 

  비정상 종료 시 다시 실행

  정상 종료 시 완료

 

job.yaml

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

 

restartPolicy

apiVersion: batch/v1
kind: job
metadata:
  name: job-example
spec:
  template:
    spec:
      containers:
      - name: centos-container
        image: centos:7
        command: ["bash"]
        args:
        - "-c"
        - "echo 'Hello World'; sleep 50; echo 'Bye'"
#      restartPolicy: Never
      restartPolicy: OnFailure
  backoffLimit: 3

restartPolicy: Never  정상 종료일 때 재시작

restartPolicy: Onfailure 비정상 종료일 때 재시작 

backoffLimit: 3 작업에 실패할 경우 재시도 횟수 

 

Job 개수 조정

apiVersion: batch/v1
kind: job
metadata:
  name: job-example
spec:
  completions: 5
  template:
    spec:
      containers:
      - name: centos-container
        image: centos:7
        command: ["bash"]
        args:
        - "-c"
        - "echo 'Hello World'; sleep 50; echo 'Bye'"
#      restartPolicy: Never
      restartPolicy: OnFailure
  backoffLimit: 3

completions: 5 5개의 작업이 완료될 때 까지 실행 

 

Job 병렬 실행

apiVersion: batch/v1
kind: job
metadata:
  name: job-example
spec:
  completions: 5
  parallelism: 2
  template:
    spec:
      containers:
      - name: centos-container
        image: centos:7
        command: ["bash"]
        args:
        - "-c"
        - "echo 'Hello World'; sleep 50; echo 'Bye'"
#      restartPolicy: Never
      restartPolicy: OnFailure
  backoffLimit: 3

parallelism: 병렬성. 동시 running되는 Pod의 수 

 

Job deadline

apiVersion: batch/v1
kind: job
metadata:
  name: job-example
spec:
  completions: 5
  parallelism: 2
  activeDeadlineSeconds: 15
  template:
    spec:
      containers:
      - name: centos-container
        image: centos:7
        command: ["bash"]
        args:
        - "-c"
        - "echo 'Hello World'; sleep 50; echo 'Bye'"
#      restartPolicy: Never
      restartPolicy: OnFailure
  backoffLimit: 3

activeDeadlineSeconds: 지정 시간 내에 Job을 완료