본문 바로가기
카테고리 없음

Federated Multi-Cluster GitOps as Code

by frontier12 2025. 5. 29.


Cluster API + Argo CD + Submariner + OPA Gatekeeper를 연동해, 온프레미스·퍼블릭·엣지에 분산된 Kubernetes 클러스터들을 단일 GitOps 워크플로우로 통합 관리하고, 네트워크·보안·애플리케이션 배포까지 코드로 선언·자동화하는 파이프라인을 구축합니다.



🎯 목표
1. Cluster API로 멀티 클라우드·온프레미스 클러스터 프로비저닝
2. Submariner로 클러스터 간 서비스·네트워크 연결(모든 네임스페이스)
3. Argo CD ApplicationSet으로 모든 클러스터에 동기화되는 GitOps 배포
4. OPA Gatekeeper로 전 클러스터 공통 보안·컴플라이언스 정책 실행
5. 자동 Self-Heal: 클러스터 드리프트·정책 위반 시 즉시 복구 및 알림



⚙️ 핵심 컴포넌트

역할 도구/CRD 설명
클러스터 프로비전 Cluster API (CAPA/CAPAWS) AWS/GCP/On-Premise에 일관된 Kubernetes 클러스터 선언·관리
멀티 클러스터 네트워킹 Submariner 클러스터 간 Pod-to-Pod, Service-to-Service 네트워크 펌프링
GitOps 배포 Argo CD ApplicationSet 다수의 클러스터에 걸친 Manifest 동기화
보안 정책 OPA Gatekeeper 공통 ConstraintTemplate/Constraints로 네임스페이스·리소스 제어
모니터링 & 복구 Prometheus + Alertmanager + Argo CD Self-Heal 드리프트·정책 위반 탐지 → Self-Heal / Slack 알림




🏗️ 파이프라인 워크플로우

flowchart TD
  subgraph Provision
    A[Git Push: Cluster API Manifests] --> B[Cluster API Controllers]
    B --> C[K8s Clusters: AWS, GCP, On-Prem]
  end

  subgraph Networking
    C --> D[Submariner Broker]
    C --> E[Submariner Agents]
    D & E --> F[Cross-Cluster Networking]
  end

  subgraph GitOps
    G[Git Push: Apps & Policies] --> H[Argo CD ApplicationSet]
    H --> I{Clusters}
    I --> C
  end

  subgraph Security & Recovery
    C --> J[OPA Gatekeeper Admission]
    C --> K[Prometheus Rules + Alerts]
    K --> L[Argo CD Self-Heal / Slack]
  end




🧪 예시 Manifest

1) Cluster API MachineDeployment (AWS)

apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
  name: md-aws-us-west-2
  namespace: capi-system
spec:
  clusterName: aws-cluster
  replicas: 3
  template:
    spec:
      bootstrap:
        configRef:
          apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
          kind: KubeadmConfigTemplate
          name: aws-md-0
      infrastructureRef:
        apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
        kind: AWSMachineTemplate
        name: aws-md-0

2) Submariner Broker (gitops/net)

apiVersion: submariner.io/v1alpha1
kind: Broker
metadata:
  name: cluster-broker
  namespace: submariner-operator
spec:
  defaultCustomDomains:
  - domain: svc.cluster.local
  secureServiceDiscovery: true

3) Argo CD ApplicationSet for Apps

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: federated-apps
spec:
  generators:
    - clusterDecisionResource:
        labelSelector:
          matchLabels: "environment=prod"
        requeueAfterSeconds: 300
  template:
    metadata:
      name: '{{cluster}}-myapp'
    spec:
      project: default
      source:
        repoURL: https://github.com/myorg/federated-configs
        path: apps/myapp
      destination:
        server: '{{server}}'
        namespace: myapp
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
          - Validate=true

4) OPA Gatekeeper Constraint (No hostPath)

apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
  name: k8snohostpath
spec:
  crd:
    spec:
      names:
        kind: K8sNoHostPath
  targets:
    - target: admission.k8s.gatekeeper.sh
      rego: |
        package k8snohostpath
        violation[{"msg": "hostPath 볼륨은 사용 금지"}] {
          vol := input.review.object.spec.template.spec.volumes[_]
          vol.hostPath
        }




✅ 기대 효과
• 풀리 Cisco-to-Any: AWS/GCP/On-Prem/Edge 클러스터까지 코드로 일관 관리
• 원클릭 네트워킹: Submariner를 통해 클러스터 간 서비스 망 자동 구성
• GitOps 일관성: 한 저장소로 전체 클러스터·앱·정책 동기화