일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- recreate
- kubeadm
- NCP
- 자동화
- helm
- terraform
- cloud monitor
- alibaba cloud
- Cluster
- cicd
- IAC
- k8s
- cloudmonitor
- slack
- CKAD
- 네이버클라우드
- argocd
- Kubernetes
- RollingUpdate
- alibabacloud
- hashicorp
- Deployment
- 테라폼
- alibaba
- 시험
- 알리바바클라우드
- slack app
- Naver Cloud
- GIT
- 쿠버네티스
- Today
- Total
Room9
CKAD - Application Design and Build (Job/CronJob) 본문

Job
잡에서 하나 이상의 파드를 생성하고 지정된 수의 파드가 성공적으로 종료될 때까지 계속해서 파드의 실행을 재시도한다.
파드가 성공적으로 완료되면, 성공적으로 완료된 잡을 추적한다.
지정된 수의 성공 완료에 도달하면, 작업(즉, 잡)이 완료된다. 잡을 삭제하면 잡이 생성한 파드가 정리된다.
작업을 일시 중지하면 작업이 다시 재개될 때까지 활성 파드가 삭제된다.
간단한 사례는 잡 오브젝트를 하나 생성해서 파드 하나를 안정적으로 실행하고 완료하는 것이다.
첫 번째 파드가 실패 또는 삭제된 경우(예로는 노드 하드웨어의 실패 또는 노드 재부팅) 잡 오브젝트는 새로운 파드를 기동시킨다.
잡을 사용하면 여러 파드를 병렬로 실행할 수도 있다.
잡을 스케줄에 따라 구동하고 싶은 경우(단일 작업이든, 여러 작업의 병렬 수행이든), 크론잡(CronJob)을 참고한다.
KodeKloud
POD DESIGN, JOBS AND CRONJOBS
Q1. A pod definition file named throw-dice-pod. yaml is given.
The image throw-dice randomly returns a value between 1 and 6.
6 is considered success and all others are failure.
Try deploying the POD and view the POD logs for the generated number.
root@controlplane:~# kubectl apply -f throw-dice-pod.yaml
pod/throw-dice-pod created
root@controlplane:~# kubectl get pods
NAME READY STATUS RESTARTS AGE
throw-dice-pod 0/1 Completed 0 4s
root@controlplane:~#
Q2.Create a Job using this POD definition. Look at how many attempts does it take to get a '6'.
Use the specification given on the right.
root@controlplane:~# kubectl delete pod throw-dice-pod
pod "throw-dice-pod" deleted
root@controlplane:~# vi job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: throw-dice-job
spec:
template:
spec:
containers:
- image: kodekloud/throw-dice
name: throw-dice
restartPolicy: Never
root@controlplane:~# kubectl apply -f job.yaml
job.batch/throw-dice-job created
root@controlplane:~# kubectl get pod
NAME READY STATUS RESTARTS AGE
throw-dice-job-75lw7 0/1 Error 0 13s
throw-dice-job-cc7kg 0/1 Error 0 33s
throw-dice-job-cpqjf 0/1 Error 0 43s
throw-dice-job-szwlm 0/1 Error 0 45s
root@controlplane:~# kubectl get job
NAME COMPLETIONS DURATION AGE
throw-dice-job 0/1 48s 48s
root@controlplane:~#
Q3.Monitor and wait for the job to succeed. Throughout this practice test remember to increase the 'BackOffLimit' to prevent the job from quitting before it succeeds.
apiVersion: batch/v1
kind: Job
metadata:
name: throw-dice-job
spec:
template:
spec:
containers:
- image: kodekloud/throw-dice
name: throw-dice
restartPolicy: Never
backoffLimit: 100
root@controlplane:~# kubectl get pods
NAME READY STATUS RESTARTS AGE
throw-dice-job-7lz4v 0/1 Completed 0 27s
throw-dice-job-zmfgx 0/1 Error 0 29s
root@controlplane:~# kubectl get jobs.batch
NAME COMPLETIONS DURATION AGE
throw-dice-job 1/1 6s 36s
Q4.How many attempts did it take to complete the job
> Q3.에서 completed 하기 위해 몇번을 시도 하였습니까
> 2
Q5. Update the job definition to run as many times as required to get 3 successful 6's
Delete existing job and create a new one with the given spec. Monitor and wait for the job to succeed.
apiVersion: batch/v1
kind: Job
metadata:
name: throw-dice-job
spec:
template:
spec:
containers:
- image: kodekloud/throw-dice
name: throw-dice
restartPolicy: Never
backoffLimit: 100
completions: 3
root@controlplane:~# kubectl get job -w
NAME COMPLETIONS DURATION AGE
throw-dice-job 0/3 12s 12s
throw-dice-job 0/3 13s 13s
throw-dice-job 1/3 15s 15s
throw-dice-job 2/3 18s 18s
throw-dice-job 2/3 20s 20s
throw-dice-job 3/3 23s 23s
^Croot@controlplane:~# kubectl get pods
NAME READY STATUS RESTARTS AGE
throw-dice-job-gfbjg 0/1 Completed 0 9s
throw-dice-job-lkkq4 0/1 Error 0 26s
throw-dice-job-rwlw4 0/1 Completed 0 14s
throw-dice-job-tgw6r 0/1 Completed 0 16s
throw-dice-job-tlvlf 0/1 Error 0 29s
throw-dice-job-vds6l 0/1 Error 0 11s
root@controlplane:~#
Q6.How many attempts did it take to complete the job this time?
> 6
Q7. That took a while. Let us try to speed it up, by running upto 3 jobs in parallel.
Update the job definition to run 3 jobs in parallel.
apiVersion: batch/v1
kind: Job
metadata:
name: throw-dice-job
spec:
template:
spec:
containers:
- image: kodekloud/throw-dice
name: throw-dice
restartPolicy: Never
backoffLimit: 100
completions: 3
parallelism: 3
root@controlplane:~# kubectl get pod -w
NAME READY STATUS RESTARTS AGE
throw-dice-job-62489 0/1 ContainerCreating 0 7s
throw-dice-job-hpjz4 0/1 ContainerCreating 0 7s
throw-dice-job-rmb4s 0/1 ContainerCreating 0 7s
throw-dice-job-hpjz4 0/1 Completed 0 10s
throw-dice-job-62489 0/1 Error 0 10s
throw-dice-job-7h7ls 0/1 Pending 0 0s
throw-dice-job-7h7ls 0/1 Pending 0 0s
throw-dice-job-7h7ls 0/1 ContainerCreating 0 0s
throw-dice-job-rmb4s 0/1 Error 0 12s
throw-dice-job-7h7ls 0/1 Error 0 4s
throw-dice-job-65lv7 0/1 Pending 0 0s
throw-dice-job-65lv7 0/1 Pending 0 0s
throw-dice-job-vftnx 0/1 Pending 0 0s
throw-dice-job-vftnx 0/1 Pending 0 0s
throw-dice-job-65lv7 0/1 ContainerCreating 0 0s
throw-dice-job-vftnx 0/1 ContainerCreating 0 0s
throw-dice-job-65lv7 0/1 Completed 0 4s
throw-dice-job-vftnx 0/1 Completed 0 4s
^Z
[1]+ Stopped kubectl get pod -w
root@controlplane:~# kubectl get job
NAME COMPLETIONS DURATION AGE
throw-dice-job 3/3 23s 61s
Q9.Let us now schedule that job to run at 21:30 hours every day. Create a CronJob for this
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: throw-dice-cron-job
spec:
schedule: "30 21 * * *"
jobTemplate:
spec:
backoffLimit: 25
completions: 3
parallelism: 3
template:
spec:
containers:
- name: throw-dice
image: kodekloud/throw-dice
restartPolicy: Never
job과 cronjob yaml 파일 들여쓰기 차이점을 확인필요
CronJob
크론잡은 반복 일정에 따라 잡을 만든다.
하나의 크론잡 오브젝트는 크론탭 (크론 테이블) 파일의 한 줄과 같다.
크론잡은 잡을 크론 형식으로 쓰여진 주어진 일정에 따라 주기적으로 동작시킨다.
추가로, 크론잡 스케줄은 타임존(timezone) 처리를 지원해서, 크론잡 스케줄 시작 부분에 "CRON_TZ="을 추가해서 타임존을 명기할 수 있으며, 항상 CRON_TZ를 설정하는 것을 권장한다.
크론잡은 백업, 리포트 생성 등의 정기적 작업을 수행하기 위해 사용된다. 각 작업은 무기한 반복되도록 구성해야 한다(예: 1일/1주/1달마다 1회). 작업을 시작해야 하는 해당 간격 내 특정 시점을 정의할 수 있다.
References
https://kubernetes.io/ko/docs/concepts/workloads/controllers/job/
잡
잡에서 하나 이상의 파드를 생성하고 지정된 수의 파드가 성공적으로 종료될 때까지 계속해서 파드의 실행을 재시도한다. 파드가 성공적으로 완료되면, 성공적으로 완료된 잡을 추적한다. 지정
kubernetes.io
https://kubernetes.io/ko/docs/concepts/workloads/controllers/cron-jobs/
크론잡
FEATURE STATE: Kubernetes v1.21 [stable] 크론잡은 반복 일정에 따라 잡을 만든다. 하나의 크론잡 오브젝트는 크론탭 (크론 테이블) 파일의 한 줄과 같다. 크론잡은 잡을 크론 형식으로 쓰여진 주어진 일정
kubernetes.io