VM 환경에서 구축된 톰캣 서비스를 k8s로 이관함에 따라 크론탭 설정이 불가한것을 확인함

PVC(nfs-server) 마운트 서버에 크론탭을 걸기엔 ERP,GW,기타 보안 등 서비스를 올린 상품이 많아 위험하기에 

크론잡을 도입하기로 함.

 

크론잡을 설정하기 위해 무엇이 필요할까

---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: test-cronjob
  namespace: test
spec:
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
  schedule: "44 1 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: test-cron
            image: harbor.test.com/test/dev:num
            imagePullPolicy: IfNotPresent
            env:
              - name: TZ
                value: "Asia/Seoul"
            command:
            - /bin/sh
            - -c
            - |
              find /mnt/app/log -type f -mtime +30 -exec rm -f {} \;
            volumeMounts:
            - name: pvc-test
              mountPath: /mnt/app
          restartPolicy: OnFailure
          volumes:
          - name: pvc-test
            persistentVolumeClaim:
              claimName: pvc-test
          imagePullSecrets:
          - name: regcred

pvc 마운트 경로는 /mnt로 되어있다.

이후 app에 개발 소스파일들이 들어가있는 구조로 tomcat 기본 설치와 동일하게 구축이 되어있다. 

 

그렇기에 /mnt/app/log를 통해 Catalina log 수집하는 데이터를 30일간 보존할수 있게 구성하였다.

 

[cloud-user@master01 ~]$ k get pods -A | grep test 
test                   test-cronjob-29011784-gmxg9                                 0/1     Completed                0                 5d5h
test                   test-deployment-775b4b94cb-sdkts                            1/1     Running                  0                 5d3h
test                   test-relay-deployment-7549ddbcfd-bm2df                      1/1     Running                  0                 117d
[cloud-user@master01 ~]$ k get cj -A | grep test
test           test-cronjob           44 1 * * *        False     5        5h29m           8d

정상 작동하는 모습.

+ Recent posts