2021. 4. 5. 19:56γπ― OpenSource/K8S
Pod, ReplicaSet, DaemonSet λ±μΌλ‘ μμ±ν νλ‘μΈμ€λ μ§μμ μΌλ‘ λμλλ©°, λ³λμ μλ£ μμ μ΄ μλ€.
λ°λ©΄ μλ£λ ν λ€μ μμλμ§ μλ νλ‘μΈμ€λ₯Ό Job 리μμ€λ‘ ꡬνν μ μλ€.
4.5.1 Job μκ°
Jobμ μμ μ΄ μ λλ‘ μλ£λμ΄μΌ νλ μμ μμ μ μ μ©νκ² μ°μΈλ€.
JobμΌλ‘ κ΄λ¦¬νλ podλ νλ‘μΈμ€κ° μλ£λκΈ° μ κΉμ§λ λμνλλ‘ μ΄μλλ€.
μλ₯Ό λ€μ΄ νλμ nodeμ μ₯μ κ° μκ²Όμλ κ·Έ μμμ λμνλ JobμΌλ‘ μμ±ν podλ λ€λ₯Έ nodeμ μλ μ€μΌμ€λ§ λλ€.
4.5.2 Job Resource
Job 리μμ€λ₯Ό μμ±νλ€.
μλ yaml μ μμμ μ¬μ©ν imageλ 120μ΄ λμ μ€νν ν μ’ λ£λλ€.
apiVersion: batch/v1
kind: Job
metadata:
name: batch-job
spec:
template:
metadata:
labels:
app: batch-job
spec:
restartPolicy: OnFailure
containers:
- name: main
image: luksa/batch-job
- apiVersion: Jobμ batch API κ·Έλ£Ήμ μνλ©°, v1μ ν΄λΉνλ€.
- spec: 컨ν μ΄λμ νλ‘μΈμ€κ° μ’ λ£λ λ μΏ λ²λ€ν°μ€κ° μνν μμ μ μ§μ νλ€.
- spec/restartPolicy: Jobμ κΈ°λ³Έμ μΌλ‘ μ¬μμ(Always) μ μ± μ μ¬μ©ν μ μλ€. podμ λμμ΄ μ€ν¨νμ κ²½μ° restart νλλ‘ νλ€. (OnFailure/Never λ₯Ό valueλ‘ μ¬μ©νλ€)
root@master001:~/k8s_in_action/kubernetes-in-action/Chapter04# kubectl create -f batch-job.yaml
job.batch/batch-job created
root@master001:~/k8s_in_action/kubernetes-in-action/Chapter04# kubectl get po
NAME READY STATUS RESTARTS AGE
batch-job-b5sdv 1/1 Running 0 6s
root@master001:~# kubectl get jobs
NAME COMPLETIONS DURATION AGE
batch-job 1/1 2m5s 19m
ν΄λΉ podμ λ‘κ·Έλ₯Ό 보면 120μ΄ ν μ’ λ£λμμμ λ³Ό μ μλ€.
root@master001:~/k8s_in_action/kubernetes-in-action/Chapter04/batch-job# kubectl logs batch-job-b5sdv
Mon Apr 5 08:45:59 UTC 2021 Batch job starting
Mon Apr 5 08:47:59 UTC 2021 Finished succesfully
4.5.3 Jobμμ μ¬λ¬ Pod μΈμ€ν΄μ€ μ€ννκΈ°
jobμ μ¬μ©νμ¬ λ κ° μ΄μμ pod μΈμ€ν΄μ€λ₯Ό μμ±ν΄ λ³λ ¬ νΉμ μμ°¨μ μΌλ‘ μ€ννλλ‘ ν μ μλ€.
jobμ specμ completionsμ parallelism μμ±μ μ€μ νλ€.
πΉ μμ°¨μ μΌλ‘ Pod μ€ννκΈ°
completions : jobμ podλ₯Ό λͺ λ² μ€νν μ§ μ€μ νλ€.
μ΄ κ²½μ° completionsμ 5λ‘ μ€μ νμλ€.
μλ£λ pod νμ μλ‘μ΄ podλ₯Ό μμ±νμ¬ κ²°κ³Όμ μΌλ‘λ μ°μμ μΌλ‘ 5κ°μ podλ₯Ό μ€ννλλ‘ νλ€.
apiVersion: batch/v1
kind: Job
metadata:
name: multi-completion-batch-job
spec:
completions: 5
template:
metadata:
labels:
app: batch-job
spec:
restartPolicy: OnFailure
containers:
- name: main
image: luksa/batch-job
λν ν΄λΉ jobμ΄ λλλ©΄ podλ completed μνκ° λλ€.
root@master001:~/k8s_in_action/kubernetes-in-action/Chapter04# kubectl get po
NAME READY STATUS RESTARTS AGE
batch-job-b5sdv 0/1 Completed 0 53m
πΉ λ³λ ¬λ‘ Pod μ€ννκΈ°
parallelism : μ¬λ¬ jobμ΄ λ³λ ¬λ‘ μ€νλλλ‘ νλ€.
completionμ 5λ‘ νμ¬ μ΄ 5κ°μ podλ₯Ό μλ£νλλ‘ μ€μ νμΌλ©°,
νλ²μ λ κ°κΉμ§ λ³λ ¬λ‘ μ€νν μ μλ€.
apiVersion: batch/v1
kind: Job
metadata:
name: multi-completion-batch-job
spec:
completions: 5
parallelism: 2
template:
metadata:
labels:
app: batch-job
spec:
restartPolicy: OnFailure
containers:
- name: main
image: luksa/batch-job
μ€νμν€λ©΄ μ΄μ κ°μ΄ λκ°μ podκ° λ³λ ¬λ‘ μ€νλ κ²μ λ³Ό μ μλ€. λ κ°μ podκ° μλ£λ νμλ λ€μ 2κ°μ podκ° μμ±λλ€.
root@master001:~/k8s_in_action/kubernetes-in-action/Chapter04# kubectl get po
NAME READY STATUS RESTARTS AGE
multi-completion-batch-job-nlhvs 1/1 Running 0 100s
multi-completion-batch-job-slr7h 1/1 Running 0 100s
root@master001:~/k8s_in_action/kubernetes-in-action/Chapter04# kubectl get po
NAME READY STATUS RESTARTS AGE
multi-completion-batch-job-4r5kx 1/1 Running 0 52s
multi-completion-batch-job-nlhvs 0/1 Completed 0 2m55s
multi-completion-batch-job-slr7h 0/1 Completed 0 2m55s
multi-completion-batch-job-w6qzg 1/1 Running 0 49s
root@master001:~/k8s_in_action/kubernetes-in-action/Chapter04# kubectl get po
NAME READY STATUS RESTARTS AGE
multi-completion-batch-job-4r5kx 0/1 Completed 0 12m
multi-completion-batch-job-kdprb 0/1 Completed 0 10m
multi-completion-batch-job-nlhvs 0/1 Completed 0 14m
multi-completion-batch-job-slr7h 0/1 Completed 0 14m
multi-completion-batch-job-w6qzg 0/1 Completed 0 12m
4.5.5 μ‘ podκ° μλ£λλ λ° κ±Έλ¦¬λ μκ° μ ννκΈ°
Jobμ΄ νΉμ μνμ λΉ μ Έ μλ£ν μ μλκ²½μ° activeDeadlineSeconds μμ±μΌλ‘ podμ μ€ν μκ°μ μ νν μ μλ€.
Podκ° μ΄λ³΄λ€ μ€λ μ€νλλ©΄ μμ€ν μ΄ μ’ λ£λ₯Ό μλνκ³ , ν΄λΉ jobμ μ€ν¨λ‘ λ¨λλ€.
4.6 Jobμ μ£ΌκΈ°μ μΌλ‘ λλ ν λ² μ€νλλλ‘ μ€μΌμ€λ§ νκΈ°
리λ μ€μμμ cron μμ μ kubernetesμμλ μ€νν μ μλ€.
yaml νμΌμμ cronjobμμμ λ§λ€μ΄μ ꡬμ±νλ€.
4.6.1 ν¬λ‘ μ‘ μμ±νκΈ°
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: batch-job-every-fifteen-minutes
spec:
schedule: "0,15,30,45 * * * *"
jobTemplate:
spec:
template:
metadata:
labels:
app: periodic-batch-job
spec:
restartPolicy: OnFailure
containers:
- name: main
image: luksa/batch-job
μ€μΌμ€μ€μ νκΈ°
crontabμμ μ¬μ©νλ λ°©μκ³Ό λμΌνλ€.
λΆ μ μΌ μ μμΌ μμΌλ‘ λμ΄νλ©°, *λ‘ κΈ°μ λ κ²½μ° λ§€ λ¨μλ§λ€ λμμν΄μ μλ―Ένλ€.
μμ yamlνμΌλ‘ 리μμ€λ₯Ό μμ±νλ€ λ€μκ³Ό κ°μ΄ μ‘°νν μ μλ€.
root@master001:~/k8s_in_action/kubernetes-in-action/Chapter04# kubectl get cronjob
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
batch-job-every-fifteen-minutes 0,15,30,45 * * * * False 0 <none> 28s
4.6.2 μ€μΌμ€λ Jobμ μ€ν λ°©λ² μ΄ν΄
Job 리μμ€λ Crontab 리μμ€μμ μμ λ μκ°μ μμ±λκ³ , jobμ podλ₯Ό μμ±νλ€.
Jobμ΄λ Podκ°μλμ μΌλ‘ λ¦κ² μμ±/μ€νλ μλ μκΈ° λλ¬Έμ μκ°μ λͺ νν μ§ν€κ² νλ €λ©΄ λ³λμ μ€μ μ΄ νμνλ€.
startingDaedlineSeconds νλλ₯Ό μ§μ νλ€.
ν΄λΉ μ΅μ μ μμ λ μκ°μμ λ¦μ΄λ 15μ΄ μμλ μ€ν λμ΄μΌ νλ©°, μ λ κ²½μ° μ€ν¨λ‘ λνλΈλ€.
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: batch-job-every-fifteen-minutes
spec:
schedule: "* 30 * * *"
startingDeadlineSeconds: 15
'π― OpenSource > K8S' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
11. Secret (0) | 2021.05.09 |
---|---|
10. ConfigMap (0) | 2021.05.08 |
08. DaemonSet (0) | 2021.04.05 |
07. ReplicaSet (0) | 2021.04.05 |
06. liveness probe (0) | 2021.04.05 |