PaaS/CI CD

ArgoCD) Git-Sync를 통하여 주기적으로 git repo fetch 받아오게 하기

armyost 2024. 12. 27. 21:43
728x90

가끔식 kustomization이나 Submodule과 같은 경우 다른 Repository의 최신 버전을 참고해야 할 때가 있다. 

 

이때는 ArgoCD 의 구성요소중 argocd-repo-server를 활용하여야 한다. 참고로 argocd-repo-server는 argocd에서 repository에 대한 fetch를 받을때 사용하는 컴포넌트로써 /tmp 경로 하위에 fetch 받은 repo의 Cache가 쌓인다. 여기서 먼저 질의한후 없으면 실제 repo에서 fetch 받는 구조이다. 

https://argo-cd.readthedocs.io/en/stable/operator-manual/server-commands/argocd-repo-server/#argocd-repo-server

 

 

이 argocd-repo-server에 Sidecar로 git-sync를 추가하여 Git Sync를 이용한 최신 Repo 참조 방법을 설명코자 한다. 

 

우선 Git-Sync가 repository에서 주기적으로 fetch하기 위하여 필요한 인증정보를 secret으로 만든다. 

이 인증정보는 Github을 SSH로 접속하는 Secret이다. 제 포스팅 중에 Github SSH 접속 편을 참고바란다.

 

 

이 Secret을 나중에 sidecar인 Git-Sync에 volume으로 추가할 예정이다. 

 

이제 argocd-repo-server에 Sidecar추가 및 Sidecar와 volume을 공유하자.

      - name: argocd-repo-server
...
        volumeMounts:
        - name: repo
          mountPath: /repo
        - name: git-secret
          mountPath: /etc/git-secret
...
      - name: git-sync ## SideCar
        image: k8s.gcr.io/git-sync:v3.1.5
        args:
        - "--ssh"
        - "--repo=git@github.com:{owner}/{repoName}"
        - "--branch={branchName}"
        - "--depth=1"
        - "--wait=60"
        volumeMounts:
        - name: repo
          mountPath: /root/git
        - name: git-secret
          mountPath: /etc/git-secret
        securityContext:
          runAsUser: 0
...
       volumes:
       - name: git-secret
         secret:
           secretName: git-secret
           defaultMode: 0400
       - name: repo
         emptyDir: {}

 

이렇게 argocd-repo-server 를 deploy하면 다음과 같이 git-sync가 주기적으로 fetch를 받아옴을 알수 있다. 

 

 

argocd-repo-server 내에서 /repo 경로에는 실제로 Sync받아온 repo 파일이 보인다.