GitOps는 Git을 단일 진실의 원천(Single Source of Truth)으로 사용하는 운영 패러다임입니다. ArgoCD와 GitHub Actions를 조합하여 완전 자동화된 Kubernetes 배포 파이프라인을 구축하세요.
GitOps is an operational paradigm using Git as the Single Source of Truth. Build a fully automated Kubernetes deployment pipeline combining ArgoCD and GitHub Actions.
GitOps 개념 이해 Understanding GitOps
GitOps는 선언적 인프라와 애플리케이션 정의를 Git 저장소에 저장하고, 자동화된 프로세스가 실제 상태를 원하는 상태와 일치시킵니다.
GitOps stores declarative infrastructure and application definitions in Git repositories, with automated processes reconciling actual state to desired state.
🔄 GitOps 핵심 원칙 🔄 GitOps Core Principles
- 선언적: 시스템 상태를 선언적으로 정의
- 버전 관리: Git으로 모든 변경 이력 추적
- 자동 적용: 승인된 변경은 자동으로 적용
- 자가 치유: 드리프트 감지 및 자동 복구
- Declarative: Define system state declaratively
- Versioned: Track all changes with Git
- Auto-applied: Approved changes apply automatically
- Self-healing: Detect drift and auto-remediate
ArgoCD 설치 및 설정 ArgoCD Installation & Setup
ArgoCD는 가장 인기 있는 Kubernetes용 GitOps CD 도구입니다. Git 저장소를 감시하고 변경 사항을 자동으로 클러스터에 동기화합니다.
ArgoCD is the most popular GitOps CD tool for Kubernetes. It watches Git repositories and automatically syncs changes to clusters.
$ kubectl create namespace argocd
$ kubectl apply -n argocd -f \
https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# ArgoCD CLI 설치 (macOS)
$ brew install argocd
# 초기 admin 비밀번호 확인
$ kubectl -n argocd get secret argocd-initial-admin-secret \
-o jsonpath="{.data.password}" | base64 -d
# ArgoCD UI 포트포워딩
$ kubectl port-forward svc/argocd-server -n argocd 8080:443
$ kubectl create namespace argocd
$ kubectl apply -n argocd -f \
https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# Install ArgoCD CLI (macOS)
$ brew install argocd
# Get initial admin password
$ kubectl -n argocd get secret argocd-initial-admin-secret \
-o jsonpath="{.data.password}" | base64 -d
# Port-forward ArgoCD UI
$ kubectl port-forward svc/argocd-server -n argocd 8080:443
Application 리소스 정의 Application Resource Definition
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/myorg/my-app
targetRevision: HEAD
path: k8s/overlays/production
destination:
server: https://kubernetes.default.svc
namespace: production
syncPolicy:
automated:
prune: true
selfHeal: true
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/myorg/my-app
targetRevision: HEAD
path: k8s/overlays/production
destination:
server: https://kubernetes.default.svc
namespace: production
syncPolicy:
automated:
prune: true
selfHeal: true
GitHub Actions CI 파이프라인 GitHub Actions CI Pipeline
GitHub Actions로 이미지 빌드, 테스트, 그리고 매니페스트 업데이트를 자동화합니다. ArgoCD가 변경된 매니페스트를 감지하여 배포합니다.
Automate image builds, tests, and manifest updates with GitHub Actions. ArgoCD detects changed manifests and deploys them.
name: CI Pipeline
on:
push:
branches: [main]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Docker 빌드 및 푸시
uses: docker/build-push-action@v5
with:
push: true
tags: ghcr.io/myorg/app:${{ github.sha }}
- name: 매니페스트 업데이트
run: |
cd k8s/base
kustomize edit set image app=ghcr.io/myorg/app:${{ github.sha }}
git commit -am "Update image to ${{ github.sha }}"
git push
name: CI Pipeline
on:
push:
branches: [main]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build and push Docker
uses: docker/build-push-action@v5
with:
push: true
tags: ghcr.io/myorg/app:${{ github.sha }}
- name: Update manifests
run: |
cd k8s/base
kustomize edit set image app=ghcr.io/myorg/app:${{ github.sha }}
git commit -am "Update image to ${{ github.sha }}"
git push
💡 Kustomize로 환경별 관리 💡 Environment Management with Kustomize
k8s/
├── base/
│ ├── deployment.yaml
│ ├── service.yaml
│ └── kustomization.yaml
└── overlays/
├── staging/
│ └── kustomization.yaml
└── production/
└── kustomization.yaml
⚠️ GitOps 보안 주의사항 ⚠️ GitOps Security Considerations
- 시크릿은 Git에 직접 커밋하지 마세요 (Sealed Secrets, SOPS 사용)
- RBAC으로 ArgoCD 접근 권한 제한
- Git 저장소에 브랜치 보호 규칙 적용
- 이미지 서명 및 검증 (Cosign)
- Never commit secrets directly to Git (use Sealed Secrets, SOPS)
- Limit ArgoCD access with RBAC
- Apply branch protection rules to Git repos
- Sign and verify images (Cosign)
