Versions Compared

Key

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

...

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 # 재시도 횟수 설정
  activeDeadlineSeconds: 100 #파드의 실행시간 설정
Code Block
linenumberstrue
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: 정해진 개수 만큼 파드가 동시에 실행 가능


    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 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 % 


    ...