본문으로 건너뛰기

Day 4 - Argo CD GitOps

Git이 원하는 상태 → 클러스터 실제 상태 동기화

목차


학습 목표

  • GitOps 푸시형 CI vs 풀형 CD를 구분한다
  • EKS에 Argo CD를 설치하고 UI/CLI로 확인한다
  • Application이 GitOps 저장소를 추적하도록 등록한다

GitOps 원칙

방식설명
Push CDCI가 kubectl apply (클러스터 자격 증명이 CI에 필요)
Pull CD (GitOps)Argo CD가 Git을 감시해 클러스터에 반영

장점: 감사(audit), 드리프트 감지, 롤백 = Git revert.


Argo CD 설치

kubectl create namespace argocd
kubectl apply -n argocd \
-f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

# 초기 admin 비밀번호
kubectl -n argocd get secret argocd-initial-admin-secret \
-o jsonpath="{.data.password}" | base64 -d; echo

# 포트 포워드 (실습)
kubectl port-forward svc/argocd-server -n argocd 8080:443
# https://localhost:8080 (admin / 위 비밀번호)

CLI:

brew install argocd # 또는 공식 바이너리
argocd login localhost:8080 --insecure

프로덕션에서는 Ingress + TLS + SSO를 권장합니다.


Application 매니페스트

GitOps 저장소 또는 클러스터 bootstrap용:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: spring-demo
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/ORG/spring-demo-gitops.git
targetRevision: main
path: apps/spring-demo
destination:
server: https://kubernetes.default.svc
namespace: spring-demo
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
kubectl apply -f argocd/application.yaml
argocd app get spring-demo
argocd app sync spring-demo # 수동 동기화가 필요할 때

Private Git 저장소는 Argo CD에 Repository credentials (HTTPS token / SSH)를 등록합니다.


동기화 정책

옵션의미
automated.pruneGit에서 삭제된 리소스를 클러스터에서도 삭제
automated.selfHeal수동 변경(드리프트)을 Git 상태로 복구
CreateNamespacedestination namespace 자동 생성

실습 초반에는 수동 sync로 동작을 확인한 뒤 automated를 켜도 됩니다.

상태 확인:

argocd app list
kubectl -n spring-demo get deploy,svc,pods

롤백

  1. Git revert (권장): 이전 커밋으로 매니페스트 되돌리기 → Argo CD sync
  2. argocd app history / argocd app rollback
  3. 이미지 태그 이전 SHA로 복구 커밋
argocd app history spring-demo
argocd app rollback spring-demo <id>

실습 체크리스트

  1. Argo CD 설치 · UI 로그인
  2. GitOps 저장소 연결 (private면 credential)
  3. Application 생성 · Healthy / Synced 확인
  4. GitOps 저장소 이미지 태그 변경 → 자동/수동 sync 확인
  5. 의도적 드리프트(kubectl scale) 후 selfHeal 동작 확인

관련 문서

그래프 뷰

그래프 데이터 로딩 중…
현재: Day 4 - Argo CD GitOps
노드 클릭 → 이동 · 드래그 → 위치 조정