Kubernetes -Job Controller

category DevOps/Kubernetes 2021. 11. 23. 22:17
728x90
반응형

Job Controller

정의

  • 쿠버네티스는 Pod를 running 중인 상태로 유지
  • Batch 처리하는 Pod는 작업이 완료되면 종료됨
  • Batch 처리에 적합한 컨트롤러로 Pod의 성공적인 완료를 보장

생성

옵션 설명
completions 실행해야 할 jobs의 수가 몇 개인지 지정
parallelism 병렬성. 동시 running되는 pod 수
activeDeadlineSeconds 지정 시간 내에 Job을 완료
옵션 설명
restartPolicy Never: Pod를 재시작, OnFailure: Container를 재시작
backoffLimit restartPolicy가 OnFailure일 경우 재시작 횟수를 지정
root@master:~# cat > job-exam.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: centos-job
spec:
  # completions: 5
  # parallelism: 5
  # activeDeadlineSeconds: 15
  template:
    spec:
      containers:
      - name: centos-container
        image: centos:7
        command: ["bash"]
        args:
        - "-c"
        - "echo 'Hello World'; sleep 10; echo 'Bye'"
      restartPolicy: Never
      # restartPolicy: OnFailure
  # backoffLimit: 3
root@master:~# kubectl create -f job-exam.yaml 
job.batch/centos-job created

조회

root@master:~# kubectl get jobs -o wide
NAME         COMPLETIONS   DURATION   AGE   CONTAINERS         IMAGES     SELECTOR
centos-job   1/1           13s        93s   centos-container   centos:7   controller-uid=6d0ee699-26c5-4aaf-8b5f-cb018e497c76
root@master:~# kubectl get pods -o wide
NAME                  READY   STATUS      RESTARTS   AGE   IP          NODE                NOMINATED NODE   READINESS GATES
centos-job--1-f8sgf   0/1     Completed   0          98s   10.44.0.1   node2.example.com   <none>           <none>

삭제

root@master:~# kubectl delete jobs.batch centos-job 
job.batch "centos-job" deleted
728x90
반응형

'DevOps > Kubernetes' 카테고리의 다른 글

Kubernetes - DaemonSet  (0) 2021.11.25
Kubernetes - CronJob  (0) 2021.11.24
Kubernetes - StatefulSet  (0) 2021.11.22
Kubernetes - ReplicaSet  (0) 2021.11.21
Kubernetes - ReplicationController  (0) 2021.11.19