배치작업의 시작
1. Kubernetes 환경일 경우 - yaml을 이용하여 배치작업 실행
Kubernetes에서의 yaml 파일을 이용한 Job 실행은 고객사의 프로젝트 환경에 따라 실행 할 수 있는 yaml을 서버에서 생성하여 관리할 필요가 있다. |
다음은 yaml 파일의 실행 예제이다.
-
배치 yaml 파일 예
kind: Job
apiVersion: batch/v1
metadata:
name: sample-init-20231113
namespace: bxcm300
spec:
template:
metadata:
labels:
app: sample-init-20231113
spec:
containers:
- name: bxcm-sample-batch
image: bxcm-sample-batch:latest
imagePullPolicy: IfNotPresent
env:
- name: BATCH_LOG_PATH
value: "/bxframework-batch-file"
command: [java, -jar, app.jar, sample-init, "test=0001", "deptNo=10"]
restartPolicy: Never
backoffLimit: 0
-
yaml 파일 실행 예
# 배치 - Kubernetes Job 실행
$ kubectl apply -f batch-sample-job.yaml
job.batch/sample-init-20231113 created
# 배치 - Kubernetes Job 실행 결과 확인
$ kubectl get po | grep sample-init
sample-init-20231113-plv9x 0/1 Completed 0 30s
# 배치 - Kubernetes Job 실행 로그 확인
$ kubectl logs -f sample-init-20231113-plv9x
08:08:10.428 [main] INFO bxmc.batch.util.BatchSystemUtils - Batch job id : [sample-init]
08:08:10.632 [main] INFO bxmc.batch.BxmCloudBatchApplication - # Input Arguments : [sample-init, test=0001]
08:08:10.662 [main] INFO bxmc.batch.BxmCloudBatchApplication - bootstrap config name : [bxframework-batch]
08:08:11.034 [main] DEBUG io.fabric8.kubernetes.client.Config - Trying to configure client from Kubernetes config...
08:08:11.034 [main] DEBUG io.fabric8.kubernetes.client.Config - Did not find Kubernetes config at: [/root/.kube/config]. Ignoring.
08:08:11.034 [main] DEBUG io.fabric8.kubernetes.client.Config - Trying to configure client from service account...
08:08:11.034 [main] DEBUG io.fabric8.kubernetes.client.Config - Found service account host and port: 10.43.0.1:443
08:08:11.040 [main] DEBUG io.fabric8.kubernetes.client.Config - Found service account ca cert at: [/var/run/secrets/kubernetes.io/serviceaccount/ca.crt}].
08:08:11.045 [main] DEBUG io.fabric8.kubernetes.client.Config - Found service account token at: [/var/run/secrets/kubernetes.io/serviceaccount/token].
08:08:11.045 [main] DEBUG io.fabric8.kubernetes.client.Config - Trying to configure client namespace from Kubernetes service account namespace path...
08:08:11.046 [main] DEBUG io.fabric8.kubernetes.client.Config - Found service account namespace at: [/var/run/secrets/kubernetes.io/serviceaccount/namespace].
08:08:12.533 [main] INFO bxmc.common.util.KubernetesUtils - KUBERNETES_SERVICE_HOST connect : [true], elapsed time : [1849]
08:08:12.533 [main] DEBUG bxmc.common.util.KubernetesUtils - set namespace : bxcm300
2023-12-01 08:08:14.143 DEBUG [bxcm-sample-batch,,] 1 --- [ main] gerReplayToApplicationContextInitializer : [] class bxmc.config.boot.LoggerReplayToApplicationContextInitializer.initialize.
2023-12-01 08:08:14.145 DEBUG [bxcm-sample-batch,,] 1 --- [ main] b.c.boot.BxmEnvironmentPostProcessor : [] spring.cloud.bootstrap.name: bxframework-batch
2023-12-01 08:08:14.948 INFO [bxcm-sample-batch,,] 1 --- [ main] o.s.c.k.f.config.Fabric8ConfigUtils : [] config-map with name : 'bxcm-sample-batch-kubernetes' not present in namespace : 'bxcm300'
2023-12-01 08:08:14.950 INFO [bxcm-sample-batch,,] 1 --- [ main] b.c.PropertySourceBootstrapConfiguration : [] Located property source: [BootstrapPropertySource {n
...