GitOps: ArgoCD

선언적 방식으로 Kubernetes 애플리케이션을 지속적으로 배포하고 관리


선언적 방식으로 Kubernetes 애플리케이션을 지속적으로 배포하고 관리

목표: GitOps 원칙에 따라 프로덕션 환경을 자동화할 수 있는 수준


🎯 GitOps 개념

원칙

graph TB
    subgraph "GitOps 원칙"
        GIT["📁 Git Repository"] -->|"1. 선언적 정의"| SYNC["🔄 동기화"]
        SYNC -->|"2. 자동 적용"| K8S["☸️ Kubernetes"]
        K8S -->|"3. 상태 모니터링"| DIFF["📊 차이 감지"]
        DIFF -->|"4. 드리프트 알림"| GIT
    end

핵심 원칙:

  1. 선언적 시스템: Git에 원하는 상태 정의
  2. 버전 관리: 모든 변경사항 Git으로 관리
  3. 자동 동기화: Git 상태를 클러스터에 자동 적용
  4. 드리프트 감지: 수동 변경 감지 및 복구

🚀 ArgoCD 설치

설치

# 네임스페이스 생성
kubectl create namespace argocd

# ArgoCD 설치
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

# CLI 설치
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

# 접근
kubectl port-forward svc/argocd-server -n argocd 8080:443

# 초기 비밀번호
argocd admin initial-password -n argocd

Helm 설치

helm repo add argo https://argoproj.github.io/argo-helm
helm install argocd argo/argo-cd \
  --namespace argocd \
  --create-namespace \
  --set server.service.type=LoadBalancer

📋 Application 정의

기본 Application

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-app
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/myorg/my-app.git
    targetRevision: HEAD
    path: k8s/overlays/production
  destination:
    server: https://kubernetes.default.svc
    namespace: production
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true

다중 소스 Application

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-app
  namespace: argocd
spec:
  project: default
  sources:
    - repoURL: https://github.com/myorg/my-app.git
      targetRevision: HEAD
      path: k8s/base
    - repoURL: https://github.com/myorg/my-app-config.git
      targetRevision: HEAD
      path: overlays/production
      ref: values
  destination:
    server: https://kubernetes.default.svc
    namespace: production

🎨 ApplicationSet

개념

여러 Application을 템플릿으로 생성.

graph TB
    subgraph "ApplicationSet"
        AS["📋 ApplicationSet"] -->|"템플릿"| A1["📦 App: dev"]
        AS -->|"템플릿"| A2["📦 App: staging"]
        AS -->|"템플릿"| A3["📦 App: prod"]
    end

Git Generator

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: my-apps
  namespace: argocd
spec:
  generators:
  - git:
      repoURL: https://github.com/myorg/my-apps.git
      revision: HEAD
      directories:
      - path: apps/*
  template:
    metadata:
      name: '{{path.basename}}'
    spec:
      project: default
      source:
        repoURL: https://github.com/myorg/my-apps.git
        targetRevision: HEAD
        path: '{{path}}'
      destination:
        server: https://kubernetes.default.svc
        namespace: '{{path.basename}}'
      syncPolicy:
        automated:
          prune: true
          selfHeal: true

Cluster Generator

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: my-app-clusters
  namespace: argocd
spec:
  generators:
  - clusters:
      selector:
        matchLabels:
          env: production
  template:
    metadata:
      name: 'my-app-{{name}}'
    spec:
      project: default
      source:
        repoURL: https://github.com/myorg/my-app.git
        targetRevision: HEAD
        path: k8s/overlays/production
      destination:
        server: '{{server}}'
        namespace: production

🔄 동기화 전략

자동 동기화

spec:
  syncPolicy:
    automated:
      prune: true        # Git에 없는 리소스 삭제
      selfHeal: true     # 수동 변경 자동 복구
      allowEmpty: false  # 빈 매니페스트 허용 안함
    syncOptions:
      - CreateNamespace=true
      - PrunePropagationPolicy=foreground
      - PruneLast=true

수동 동기화

# 동기화
argocd app sync my-app

# 동기화 (특정 리소스)
argocd app sync my-app --resource apps:Deployment:my-app

# 강제 동기화
argocd app sync my-app --force

🛡️ 보안

RBAC

apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: production
  namespace: argocd
spec:
  description: Production project
  sourceRepos:
    - https://github.com/myorg/production.git
  destinations:
    - namespace: production
      server: https://kubernetes.default.svc
  clusterResourceWhitelist:
    - group: ''
      kind: Namespace
  namespaceResourceBlacklist:
    - group: ''
      kind: ResourceQuota
  roles:
    - name: developer
      description: Developer access
      policies:
        - p, proj:production:developer, applications, get, production/*, allow
        - p, proj:production:developer, applications, sync, production/*, allow
      groups:
        - github:developers

SSO 연동

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-cm
  namespace: argocd
data:
  url: https://argocd.example.com
  dex.config: |
    connectors:
      - type: github
        id: github
        name: GitHub
        config:
          clientID: $GITHUB_CLIENT_ID
          clientSecret: $GITHUB_CLIENT_SECRET
          orgs:
            - name: myorg

📋 체크리스트

  • ArgoCD 설치
  • Git 저장소 연결
  • Application 생성
  • ApplicationSet 설정
  • 자동 동기화 구성
  • RBAC 설정
  • SSO 연동
  • 알림 설정
  • 모니터링 구성

🔗 관련 노트

  • 03-03-Helm-패키지-관리 — Helm 차트 배포
  • 03-04-Kustomize-설정-관리 — Kustomize 배포
  • 03-08-멀티클러스터-관리 — 멀티클러스터 배포

마지막 업데이트: 2026-06-01