개인에게 맞춤 추천 시스템을 사용하기에는 너무 많은 리소스가 필요하기 때문에 넷플릭스의 추천 시스템은 실시간 (OnLine) 분석, 준 실시간 (Nearline) 분석, 오프라인 (Offline) 분석으로 나누어서 사용
so 예를 들어, 리소스가 상대적으로 많이 남게 되는 새벽 시간에 리소스가 많이 들어가는 작업들 (모델링이라든지..) 등을 CronJob 형태로 실행할 수 있음.
# job-pi.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 # 재시도 횟수 4번으로 제한
.spec.comletions
에 0이 아닌 양수를 지정하면 정해진 횟수까지 파드가 반복적 실행.spec.parallelism
에 0이 아닌 양수를 지정하면 정해진 개수만큼 파드가 동시 실행 가능# job-pi-parallelism.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: pi-parallelism
spec:
completions: 5 # 목표 완료 파드 개수
parallelism: 2 # 동시 실행 가능 파드 개수
template:
spec:
containers:
- name: pi
image: perl:5.34.0
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4 # 재시도 횟수 4번으로 제한
Job 실행
# 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 # 재시도 횟수 4번으로 제한
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl create -f job.yaml
job.batch/pi created
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get job,pod
NAME COMPLETIONS DURATION AGE
job.batch/pi 0/1 22s 22s
NAME READY STATUS RESTARTS AGE
pod/nginx-sidecar 3/3 Running 0 23h
pod/pi-v2f9k 0/1 ContainerCreating 0 22s
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get job,pod
NAME COMPLETIONS DURATION AGE
job.batch/pi 1/1 33s 113s
NAME READY STATUS RESTARTS AGE
pod/nginx-sidecar 3/3 Running 0 23h
pod/pi-v2f9k 0/1 Completed 0 113s
Job 삭제
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get job
NAME COMPLETIONS DURATION AGE
pi 1/1 33s 4m6s
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl delete job pi
job.batch "pi" deleted
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-sidecar 3/3 Running 0 23h
Job 병렬 실행
# job-pi-parallelism.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: pi-parallelism
spec:
completions: 5 # 목표 완료 파드 개수
parallelism: 2 # 동시 실행 가능 파드 개수
template:
spec:
containers:
- name: pi
image: perl:5.34.0
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4 # 재시도 횟수 4번으로 제한
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl create -f job-pi-parallelism.yaml
job.batch/pi-parallelism created
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get pod,job
NAME READY STATUS RESTARTS AGE
pod/nginx-sidecar 3/3 Running 0 23h
pod/pi-parallelism-5v5f6 1/1 Running 0 5s
pod/pi-parallelism-xjphq 1/1 Running 0 5s
NAME COMPLETIONS DURATION AGE
job.batch/pi-parallelism 0/5 6s 6s
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get pod,job
NAME READY STATUS RESTARTS AGE
pod/nginx-sidecar 3/3 Running 0 23h
pod/pi-parallelism-5v5f6 0/1 Completed 0 15s
pod/pi-parallelism-xjphq 0/1 Completed 0 15s
NAME COMPLETIONS DURATION AGE
job.batch/pi-parallelism 0/5 15s 15s
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get pod,job
NAME READY STATUS RESTARTS AGE
pod/nginx-sidecar 3/3 Running 0 23h
pod/pi-parallelism-5v5f6 0/1 Completed 0 17s
pod/pi-parallelism-vjvdz 0/1 ContainerCreating 0 1s
pod/pi-parallelism-vt24c 0/1 ContainerCreating 0 1s
pod/pi-parallelism-xjphq 0/1 Completed 0 17s
NAME COMPLETIONS DURATION AGE
job.batch/pi-parallelism 2/5 17s 17s
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get pod,job
NAME READY STATUS RESTARTS AGE
pod/nginx-sidecar 3/3 Running 0 23h
pod/pi-parallelism-5v5f6 0/1 Completed 0 19s
pod/pi-parallelism-vjvdz 1/1 Running 0 3s
pod/pi-parallelism-vt24c 1/1 Running 0 3s
pod/pi-parallelism-xjphq 0/1 Completed 0 19s
NAME COMPLETIONS DURATION AGE
job.batch/pi-parallelism 2/5 20s 20s
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get pod,job
NAME READY STATUS RESTARTS AGE
pod/nginx-sidecar 3/3 Running 0 23h
pod/pi-parallelism-5v5f6 0/1 Completed 0 30s
pod/pi-parallelism-vjvdz 0/1 Completed 0 14s
pod/pi-parallelism-vt24c 0/1 Completed 0 14s
pod/pi-parallelism-xjphq 0/1 Completed 0 30s
NAME COMPLETIONS DURATION AGE
job.batch/pi-parallelism 2/5 30s 30s
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get pod,job
NAME READY STATUS RESTARTS AGE
pod/nginx-sidecar 3/3 Running 0 23h
pod/pi-parallelism-5v5f6 0/1 Completed 0 32s
pod/pi-parallelism-tn4mc 0/1 ContainerCreating 0 1s
pod/pi-parallelism-vjvdz 0/1 Completed 0 16s
pod/pi-parallelism-vt24c 0/1 Completed 0 16s
pod/pi-parallelism-xjphq 0/1 Completed 0 32s
NAME COMPLETIONS DURATION AGE
job.batch/pi-parallelism 4/5 32s 32s
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get pod,job
NAME READY STATUS RESTARTS AGE
pod/nginx-sidecar 3/3 Running 0 23h
pod/pi-parallelism-5v5f6 0/1 Completed 0 34s
pod/pi-parallelism-tn4mc 1/1 Running 0 3s
pod/pi-parallelism-vjvdz 0/1 Completed 0 18s
pod/pi-parallelism-vt24c 0/1 Completed 0 18s
pod/pi-parallelism-xjphq 0/1 Completed 0 34s
NAME COMPLETIONS DURATION AGE
job.batch/pi-parallelism 4/5 34s 34s
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get pod,job
NAME READY STATUS RESTARTS AGE
pod/nginx-sidecar 3/3 Running 0 23h
pod/pi-parallelism-5v5f6 0/1 Completed 0 38s
pod/pi-parallelism-tn4mc 0/1 Completed 0 7s
pod/pi-parallelism-vjvdz 0/1 Completed 0 22s
pod/pi-parallelism-vt24c 0/1 Completed 0 22s
pod/pi-parallelism-xjphq 0/1 Completed 0 38s
NAME COMPLETIONS DURATION AGE
job.batch/pi-parallelism 4/5 39s 39s
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get pod,job
NAME READY STATUS RESTARTS AGE
pod/nginx-sidecar 3/3 Running 0 23h
pod/pi-parallelism-5v5f6 0/1 Completed 0 41s
pod/pi-parallelism-tn4mc 0/1 Completed 0 10s
pod/pi-parallelism-vjvdz 0/1 Completed 0 25s
pod/pi-parallelism-vt24c 0/1 Completed 0 25s
pod/pi-parallelism-xjphq 0/1 Completed 0 41s
NAME COMPLETIONS DURATION AGE
job.batch/pi-parallelism 5/5 40s 41s
Job 삭제
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get job
NAME COMPLETIONS DURATION AGE
pi-parallelism 5/5 40s 9m35s
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl delete job pi-parallelism
job.batch "pi-parallelism" deleted
imkunyoung@cloudshell:~/job (k8s-inflearn)$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-sidecar 3/3 Running 0 24h