DevOps & Infra/Kubernetes

[ArgoCD] private repository 애플리케이션 생성하기

턴태 2023. 11. 6. 15:13

실무환경에서 argoCD를 사용한다면, 대부분의 repo가 private repository로 존재한다. 따라서 argoCD가 private repository에 접근할 수 있도록 권한을 잘 부여하는 것이 중요하다.

HTTPS Username, Password

사용자 이름과 비밀번호가 필요한 비공개 리포지토리는 일반적으로 git@ 또는 ssh://가 아닌 https:// 로 시작하는 URL을 사용한다.

argocd cli 를 통한 credential 설정은 다음과 같다.

argocd repo add https://github.com/argoproj/argocd-example-apps --username <username> --password <password>

 

github와 같은 저장소의 레포지터리 주소를 넣고, username과 password를 옵션값으로 넣어준다.

github를 사용하고 있다면, token을 생성해서 토큰값을 password에 입력해줘야 한다.

 

그렇게 하면 아래와 같이 추가가 완료됨을 확인할 수 있다.

 

Repository 'https://github.com/stae1102/kubernetes-nodejs-server.git' added


UI로 설정하는 방법은 다음과 같다.

 


1. Settings -> Repositories


2. CONNECT REPO


3. VIA HTTPS 선택

 

나머지 내용은 CLI 옵션과 같이 입력하면 된다.

 

TLS Client Certificates

혹은 인증서를 사용하여 레포지터리 Credentials 설정을 해야 할 때도 있다. 위에서 HTTPS Username과 Password로 권한 인증을 한 것처럼, 옵션을 추가하여 레포지터리 권한을 설정할 수 있다.

argocd repo add https://repo.example.com/repo.git --tls-client-cert-path ~/mycert.crt --tls-client-cert-key-path ~/mycert.key


`--tls-client-cert-path`, `--tls-client-cert-key-path` 의 값으로 인증서를 기입하여 설정해준다.

SSH Private key

SSH Private Key가 필요한 레포지터리는 https가 아니라 `git@` 혹은 `ssh://`로 시작하는 URL을 가지고 있다.

UI는 대부분 비슷하므로, CLI 환경만 살펴보자면 다음과 같다.

argocd repo add git@github.com:argoproj/argocd-example-apps.git --ssh-private-key-path ~/.ssh/id_rsa

 

SSH 키를 만드는 방법은 다음과 같다.

ssh-keygen -f kubernetes-nodejs-server

 

-f 옵션값으로 원하는 파일명을 작성하면 아래와 같이 공개키(.pub)와 비밀키가 생성된다.

 

이 공개 키를 깃허브 private repository에 등록하자.

 

 

위와 같이 public key를 deploy key로 등록해준 다음에 private key를 통해 argocd에 등록해주면 된다.

 

깃허브 account에서 전역적으로 ssh public key를 등록시킬 수 있을 것 같은데, 굳이 필요 없는 경우 repository 단위로도 설정할 수 있다.

 

UI 화면에서도 간단하게 추가할 수 있다.

 

HTTPS에서 설정했던 것과 같은 방법으로 Repository 추가 화면으로 접근한다.

 

이와 같이 입력한 후 CONNECT를 눌러 레포지터리가 연결됨을 확인해준다.

 

 

SSH key가 사용된 것도 확인할 수 있다.

 

정리하며

private repository가 한 가지 방법이 아니라 여러 가지 방법을 사용하여 연결해야 할 수 있으므로 어느 정도 숙지해 놓는 것은 좋은 것 같다.

참고

https://argo-cd.readthedocs.io/en/stable/user-guide/private-repositories/

 

Private Repositories - Argo CD - Declarative GitOps CD for Kubernetes

Private Repositories Note Some Git hosters - notably GitLab and possibly on-premise GitLab instances as well - require you to specify the .git suffix in the repository URL, otherwise they will send a HTTP 301 redirect to the repository URL suffixed with .g

argo-cd.readthedocs.io