Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Info
iconfalse
title목차

Table of Contents

Job 개요

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


Info
iconfalse
titleaws.plainenglish.io/kubernetes-deep-dive-job-and-cronjob-5ffed1c5fa4e

Image Added


Job Manifest

Info
iconfalse

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

Info
iconfalse
  • apiVersion: batch/v1

  • kind: Job

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


Code Block
titlejob.yaml
linenumberstrue
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
  • backoffLimit: 계속 재시도 할경우 문제가 발생할수 있음. 재실행 가능횟수
Code Block
apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    spec:
      completions: 5 # 목표 완료 파드 개수
      parallelism: 2 # 동시 실행 가능 파드 개수
      containers:
      - name: pi
        image: perl:5.34.0
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
  backoffLimit: 4
  • completions: 정해진 횟수 까지 파드가 반복적으로 실행
  • parallelism: 정해진 개수 만큼 파드가 동시에 실행 가능
     # 재시도 횟수 설정
      activeDeadlineSeconds: 100 #파드의 실행시간 설정


    Job 실습

    Info
    iconfalse
    Code Block
    linenumberstrue
    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 %