목차

Job 개요

  • Deployment와 같은 Controller객체 중 하나
  • 하나 이상의 Pod를 만들고 지정된 수의 Pod가 성공적으로 종료될 때까지 Pods실행을 계속 재시도
  • Job을 사용하여 여러 Pod를 병렬로 실행 가능(기본값 1)
  • Job사용예
    • 배치처리
    • Data Transform
    • Video, Audio Encoding


aws.plainenglish.io/kubernetes-deep-dive-job-and-cronjob-5ffed1c5fa4e


Job Manifest

https://dev-k8sref-io.web.app/docs/workloads/job-v1/

  • apiVersion: batch/v1

  • kind: Job

  • metadata (ObjectMeta)
  • spec (JobSpec)
    • template (PodTemplateSpec)
    • completions     #정해진 횟수 까지 파드가 반복적으로 실행
    • parallelism        #정해진 개수 만큼 파드가 동시에 실행 가능
    • backoffLimit    #재시도 횟수 설정
    • activeDeadlineSeconds  # 파드의 실행시간 설정
  • status (JobStatus)


job.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    spec:
      containers:
      - name: pi
        image: perl:5.34.0
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never # 파드의 재시작 정책 설정
  backoffLimit: 4 # 재시도 횟수 설정
  activeDeadlineSeconds: 100 #파드의 실행시간 설정


Job 실습

sansae@sansaeAir15m2 k8s-lab-workspace % k apply -f job.yaml 
job.batch/pi created


sansae@sansaeAir15m2 k8s-lab-workspace % k get all
NAME           READY   STATUS    RESTARTS   AGE
pod/pi-kz68s   1/1     Running   0          4s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP   48s

NAME           COMPLETIONS   DURATION   AGE
job.batch/pi   0/1           5s         5s


sansae@sansaeAir15m2 k8s-lab-workspace % k get all
NAME           READY   STATUS      RESTARTS   AGE
pod/pi-kz68s   0/1     Completed   0          18s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP   62s

NAME           COMPLETIONS   DURATION   AGE
job.batch/pi   1/1           7s         18s
sansae@sansaeAir15m2 k8s-lab-workspace % 


sansae@sansaeAir15m2 k8s-lab-workspace % k logs pi-pi-kz68s
3.14159265358979323846264338327950288419716939937510582
~~~~~~~~~~~~ 생략 ~~~~~~~~~~~~~~~~

sansae@sansaeAir15m2 k8s-lab-workspace % k describe job pi
Name:                     pi
Namespace:                default
Selector:                 batch.kubernetes.io/controller-uid=3ba192aa-4cbf-4fa4-b037-bd449d249492
Labels:                   batch.kubernetes.io/controller-uid=3ba192aa-4cbf-4fa4-b037-bd449d249492
                          batch.kubernetes.io/job-name=pi
                          controller-uid=3ba192aa-4cbf-4fa4-b037-bd449d249492
                          job-name=pi
Annotations:              batch.kubernetes.io/job-tracking: 
Parallelism:              1
Completions:              1
Completion Mode:          NonIndexed
Start Time:               Sat, 09 Mar 2024 23:57:54 +0900
Completed At:             Sat, 09 Mar 2024 23:58:01 +0900
Duration:                 7s
Active Deadline Seconds:  100s
Pods Statuses:            0 Active (0 Ready) / 1 Succeeded / 0 Failed
Pod Template:
  Labels:  batch.kubernetes.io/controller-uid=3ba192aa-4cbf-4fa4-b037-bd449d249492
           batch.kubernetes.io/job-name=pi
           controller-uid=3ba192aa-4cbf-4fa4-b037-bd449d249492
           job-name=pi
  Containers:
   pi:
    Image:      perl:5.34.0
    Port:       <none>
    Host Port:  <none>
    Command:
      perl
      -Mbignum=bpi
      -wle
      print bpi(2000)
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From            Message
  ----    ------            ----  ----            -------
  Normal  SuccessfulCreate  40s   job-controller  Created pod: pi-kz68s
  Normal  Completed         33s   job-controller  Job completed
sansae@sansaeAir15m2 k8s-lab-workspace % 



  • No labels
Write a comment…