본문 바로가기
IT & Tech 정보

Chaos Engineering 통합 끝판왕 가이드: Chaos Mesh & LitmusChaos CI 파이프라인

by 지식과 지혜의 나무 2025. 5. 26.
반응형




1. 서론: 왜 Chaos Engineering인가

현대의 마이크로서비스·쿠버네티드 환경은 복잡계입니다. 개별 리소트는 잘 돌아가도, 다양한 장애가 결합하면 예측 불가능한 시스템 전반의 장애로 이어집니다.
Chaos Engineering은 의도적으로 장애를 주입해 시스템의 복원력(Resilience) 과 모니터링·알림 체계를 검증하는 방법론입니다. 실리콘밸리·심천 최정예 팀들은 단순 실험 스크립트를 넘어, Chaos Mesh 와 LitmusChaos 를 CI 파이프라인에 결합해 End-to-End 자동화된 장애 검증·복구 테스트를 수행합니다.
• 예방적 안정성 검증: 배포 전후, 새 코드가 장애 복원력에 미치는 영향 측정
• 실시간 알림·롤백: 카오스 실험 중치명적 장애 탐지 시 자동 차단·롤백
• 지속적 개선: 실험 결과를 메트릭·로그로 저장, SLO 보완점 도출



2. 아키텍처 개요

Git Repo                 CI/CD System               Kubernetes Cluster
  │                         │                            │
  └─ push experiment.yml ─▶│                            │
                           ├─▶ LitmusChaos CI Job      │
                           │    (kubectl apply + CLI)  │
                           │                            │
                           │                            │
                           └─▶ Chaos Mesh Controller   │
                                (Chaos CRD 자동 배포)   │
                                                        ▼
                                       ┌──────────────────────────┐
                                       │  Chaos Resources (Pods,  │
                                       │  NetworkPolicies, etc.)  │
                                       ├──────────────────────────┤
                                       │  Prometheus / Grafana    │
                                       │  Alertmanager            │
                                       └──────────────────────────┘
                                                        ▲
                                                        │
                                      결과 메트릭·로그 ←┘

1. Chaos Mesh: Kubernetes 네이티브 CRD 기반 장애 실험
2. LitmusChaos: 독립 CI Job으로 다양한 카오스 시나리오 실행
3. CI/CD 연동: GitHub Actions/Jenkins 파이프라인에 chaos experiment 단계 삽입
4. 모니터링·알림: Prometheus와 Grafana, Alertmanager로 복원력 지표 수집



3. Chaos Mesh 고급 활용

3.1 설치 & CRD 배포

# Helm 리포지토리 등록
helm repo add chaos-mesh https://charts.chaos-mesh.org
helm repo update

# Namespace 생성, CRD·Controller 설치
kubectl create ns chaos-testing
helm install chaos-mesh chaos-mesh/chaos-mesh \
  --namespace=chaos-testing \
  --set dashboard.create=true \
  --set chaosDaemon.imagePullPolicy=IfNotPresent

3.2 Network Chaos 예제

# experiment/network-chaos.yaml
apiVersion: chaos-mesh.org/v1alpha1
kind: NetworkChaos
metadata:
  name: pod-network-loss
  namespace: chaos-testing
spec:
  action: loss
  mode: one
  selector:
    namespaces: ["default"]
    labelSelectors:
      "app": "frontend"
  loss:
    loss: "30%"       # 30% 패킷 손실
    correlation: "0"
  duration: "60s"
  scheduler:
    cron: "@every 5m"  # 5분마다 실행

• mode: one: 대상 파드 중 1개만 랜덤 선택
• loss/delay/jitter 등 조합 가능
• scheduler.cron: 반복 주입 자동화

3.3 IO Chaos 예제

# experiment/io-chaos.yaml
apiVersion: chaos-mesh.org/v1alpha1
kind: IoChaos
metadata:
  name: pod-disk-latency
  namespace: chaos-testing
spec:
  action: latency
  mode: all
  selector:
    namespaces: ["default"]
    labelSelectors:
      "app": "mysql"
  io:
    latency: "100ms"      # 100ms 디스크 지연
    percent: "80"         # 80% 확률
  duration: "30s"




4. LitmusChaos CI 파이프라인

4.1 Litmus 설치

kubectl apply -f https://litmuschaos.github.io/litmus/litmus-operator-v1.17.8.yaml

4.2 Chaos Experiment 정의

# experiments/pod-delete.yaml
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
  name: pod-delete-engine
  namespace: default
spec:
  annotationCheck: 'true'
  appinfo:
    appns: 'default'
    applabel: 'app=payment'
    appkind: 'Deployment'
  chaosServiceAccount: litmus-admin
  experiments:
    - name: pod-delete
      spec:
        components:
          env:
            - name: TOTAL_CHAOS_DURATION
              value: '60'   # 60초동안
            - name: FORCE
              value: 'true' # 강제 삭제

4.3 CI 스크립트 예시 (GitHub Actions)

name: Chaos Testing

on: push

jobs:
  chaos:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Apply ChaosMesh Experiments
        run: |
          kubectl apply -f experiment/network-chaos.yaml
          kubectl apply -f experiment/io-chaos.yaml

      - name: Run Litmus Experiment
        run: |
          kubectl apply -f experiments/pod-delete.yaml
          # 실험 상태 대기
          kubectl wait --for=condition=Complete chaosresult/pod-delete-engine-*
            -n default --timeout=120s

      - name: Check Results
        run: |
          STATUS=$(kubectl get chaosresult pod-delete-engine-*-pod-delete \
                    -n default -o jsonpath='{.status.engineStatus.experimentStatus.verdict}')
          if [ "$STATUS" != "Pass" ]; then
            echo "Chaos test failed: $STATUS"
            exit 1
          fi




5. 자동화 & GitOps 연동

5.1 Argo CD & Chaos Mesh
• experiment/ 디렉터리를 GitOps 레포에 포함
• Argo CD Application으로 실험 CRD 자동 동기화
• 헬프터: syncOptions: [CreateNamespace=true]

5.2 Tekton Pipeline 통합

# tekton/task-chaos.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata: name: chaos-test
spec:
  steps:
    - name: apply-chaos
      image: bitnami/kubectl
      script: |
        kubectl apply -f experiment/network-chaos.yaml
    - name: run-litmus
      image: lumen/litmus:cli
      script: |
        litmusctl chaos run pod-delete-engine

• Tekton Pipeline 에서 chaos-test 단계 삽입



6. 모니터링 & 자동 롤백
1. Prometheus
• Chaos Mesh 내 chaos_metric 수집 (e.g., chaos_duration_seconds)
• LitmusChaos chaos_duration 메트릭 연동
2. Alertmanager
• verdict!="Pass" 이벤트 알람
• PagerDuty·Slack 통합 Webhook 설정
3. 자동 롤백
• CI 스크립트 실패 시 kubectl rollout undo deployment/<app> 호출



7. “아, 이런 방법도” 팁
• Canary Chaos: NetworkChaos 단계→PodDelete 단계를 순차적 Canary로 구성
• Custom Experiments: WASM 기반 Chaos Plugin 개발
• Chaos Dashboard: Chaos Mesh Dashboard + Grafana Chaos Plugin
• Dry-Run Mode: --dry-run 플래그로 CRD YAML 검증
• Scope 제한: selector.matchExpressions로 특정 노드/존 범위 지정



8. 결론
• Chaos Mesh: Kubernetes 네이티브로 간편하고 강력한 장애 주입
• LitmusChaos: CI 파이프라인에서 시나리오별 엔드투엔드 검증
• 자동화 & GitOps: 실험 정의부터 결과 분석까지 완전 자동화

“교과서론 절대 다루지 않는, 실리콘밸리·심천 IT기업 최정예 개발자급 Chaos Engineering 통합”을 직접 구현해 보세요. 시스템 복원력을 과학적으로 검증하고, 장애에도 끄떡없는 인프라를 갖추는 그날까지!

반응형