본문 바로가기
cicd/argocd

ArgoCD CLI 사용하여 App 배포하기

by _Nate 2023. 3. 24.
반응형

ArgoCD는 CLI를 제공한다. CLI로도 모든 기능을 사용할 수 있다.


1. CLI 설치

  • Ubuntu 기준으로 아래와 같이 진행하면 된다. 별도 설치과정은 없고 단순히 binary를 받아 옮기는 정도이다.
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
rm argocd-linux-amd64

 

2. CLI로 App 배포

  • 예시로 ArgoCD를 통해 Helm을 배포해 보겠다.
  • ArgoCD CLI사용을 위해선 UI와 마찬가지로 로그인이 필요하다.
test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# argocd login 127.0.0.1:8080
WARNING: server certificate had error: x509: cannot validate certificate for 127.0.0.1 because it doesn't contain any IP SANs. Proceed insecurely (y/n)? y
Username: admin
Password:
'admin:login' logged in successfully
Context '127.0.0.1:8080' updated
  • 테스트환경이라 port-forward를 통해 접근했다.

 

  • repository 생성 및 확인
test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# argocd repo add \
https://charts.bitnami.com/bitnami --type helm --name helm-repo
Repository 'https://charts.bitnami.com/bitnami' added

test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# argocd repo list
TYPE  NAME          REPO                                          INSECURE  OCI    LFS    CREDS  STATUS      MESSAGE  PROJECT
helm  helm-repo     https://charts.bitnami.com/bitnami            false     false  false  false  Successful

 

  • cluster 추가 및 확인
test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# argocd cluster add test-cluster
WARNING: This will create a service account `argocd-manager` on the cluster referenced by context `test-cluster` with full cluster level privileges. Do you want to continue [y/N]? y
INFO[0001] ServiceAccount "argocd-manager" created in namespace "kube-system"
INFO[0001] ClusterRole "argocd-manager-role" created
INFO[0001] ClusterRoleBinding "argocd-manager-role-binding" created
INFO[0006] Created bearer token secret for ServiceAccount "argocd-manager"
Cluster 'https://FE53A82E1A035C54CE7090049E047F46.gr7.ap-northeast-2.eks.amazonaws.com' added

test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# argocd cluster list
SERVER                                                                         NAME         VERSION  STATUS      MESSAGE                                                  PROJECT
https://FE53A82E1A035C54CE7090049E047F46.gr7.ap-northeast-2.eks.amazonaws.com  test-cluster           Unknown     Cluster has no applications and is not being monitored.
  • in-cluster외에 다른 cluster를 추가할 경우 진행한다.

 

  • project 생성 및 확인
argocd proj create helmproj --src https://charts.bitnami.com/bitnami \
--dest https://FE53A82E1A035C54CE7090049E047F46.gr7.ap-northeast-2.eks.amazonaws.com,test

test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# argocd proj list
NAME         DESCRIPTION  DESTINATIONS                                                                        SOURCES                             CLUSTER-RESOURCE-WHITELIST  NAMESPACE-RESOURCE-BLACKLIST  SIGNATURE-KEYS  ORPHANED-RESOURCES
helmproj                  https://FE53A82E1A035C54CE7090049E047F46.gr7.ap-northeast-2.eks.amazonaws.com,test  https://charts.bitnami.com/bitnami  <none>                      <none>                        <none>          disabled
  • CLI를 사용해보는 목적이기 때문에 옵션은 최소로 하였으며 옵션설명도 생략하겠다.

 

  • Application 생성
test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# argocd app create helmtest \
> --repo https://charts.bitnami.com/bitnami \
> --project helmproj \
> --helm-chart nginx --revision 13.2.30 \
> --dest-namespace test --dest-name test-cluster \
> --revision-history-limit 5 \
> --validate=false \
> --sync-policy auto \
> --sync-option Prune=true
application 'helmtest' created
  • bitnami chart의 nginx를 배포하였으며 chart version은 13.2.30이다.
test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# argocd app list
NAME             CLUSTER      NAMESPACE  PROJECT   STATUS  HEALTH   SYNCPOLICY  CONDITIONS  REPO                                PATH  TARGET
argocd/helmtest  test-cluster  test       helmproj  Synced  Healthy  Auto        <none>      https://charts.bitnami.com/bitnami        13.2.30

test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# k get all -n test
NAME                                  READY   STATUS    RESTARTS   AGE
pod/helmtest-nginx-6856dcc9cb-tbm7n   0/1     Running   0          10s

NAME                     TYPE           CLUSTER-IP       EXTERNAL-IP                                                                    PORT(S)        AGE
service/helmtest-nginx   LoadBalancer   10.100.221.199   a7efd091e5587469db05dd8cb8a36168-1332581592.ap-northeast-2.elb.amazonaws.com   80:31124/TCP   11s

NAME                             READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/helmtest-nginx   0/1     1            0           11s

NAME                                        DESIRED   CURRENT   READY   AGE
replicaset.apps/helmtest-nginx-6856dcc9cb   1         1         0       11s
  • Resource들이 생성된 것을 확인할 수 있다.
  • 참고로 동일 application을 yaml형태로 생성도 가능하다.
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: helmtest
  namespace: argocd
spec:
  destination:
    name: test-cluster
    namespace: test
  project: helmproj
  revisionHistoryLimit: 5
  source:
    chart: nginx
    repoURL: https://charts.bitnami.com/bitnami
    targetRevision: 13.2.30
  syncPolicy:
    automated: {}
    syncOptions:
    - Prune=true

 

  • 생성한 resource들을 모두 삭제한다.
test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# argocd app delete helmtest
Are you sure you want to delete 'helmtest' and all its resources? [y/n] y
application 'helmtest' deleted

test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# argocd proj delete helmproj

test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# argocd cluster rm test-cluster
Are you sure you want to remove 'test-cluster'? Any Apps deploying to this cluster will go to health status Unknown.[y/n] y
Cluster 'test-cluster' removed
INFO[0002] ClusterRoleBinding "argocd-manager-role-binding" deleted
INFO[0002] ClusterRole "argocd-manager-role" deleted
INFO[0002] ServiceAccount "argocd-manager" deleted

test@DESKTOP-F55SF6V:~ (⎈|test-cluster:default)# argocd repo rm https://charts.bitnami.com/bitnami
Repository 'https://charts.bitnami.com/bitnami' removed

 

반응형

명령어가 깔끔하다는 느낌은 없다. set을 만들어 두고 사용하기엔 괜찮아 보인다.

반응형

'cicd > argocd' 카테고리의 다른 글

ArgoCD Source로 Private Git Repo 접근하기  (0) 2023.03.24
ArgoCD PRUNE과 SELF HEAL 테스트  (0) 2023.03.23
ArgoCD로 Kubernetes CD환경 구성하기  (0) 2023.03.20