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

Serverless GitOps as Code: Knative + Tekton + KEDA + Argo CD + Prometheus 기반

by frontier12 2025. 5. 29.


완전 자동화된 FaaS 플랫폼

🎯 목표

“개발자는 함수 코드만 푸시하면, 배포·빌드·서빙·오토스케일·모니터링·롤백까지 전부 코드로 자동화되는” 서버리스 GitOps 플렛폼을 구축합니다:
1. Git에 함수 코드 + 선언적 매니페스트를 푸시
2. Tekton Pipelines로 컨테이너로 빌드·테스트·레지스트리에 푸시
3. Knative Serving으로 함수(서비스) 자동 배포
4. KEDA로 이벤트 소스(Cron, Kafka, HTTP) 기반 오토스케일
5. Prometheus로 메트릭 감시 → KEDA 트리거
6. Argo CD로 매니페스트 동기화·자가 치유·버전 롤백
7. GitOps 이력으로 모든 변경·오토스케일·복구 이벤트 기록



⚙️ 핵심 구성 요소

계층 도구/CRD 역할
CI (빌드) Tekton Pipelines & Triggers 함수 코드 → 이미지 빌드·테스트·레지스트리에 푸시
서빙 Knative Serving (Service CRD) 푸시된 이미지를 FaaS 형태로 자동 배포
오토스케일링 KEDA ScaledObject HTTP 요청량, Kafka 토픽 lag, Cron Schedule 기반
모니터링 Prometheus + Alertmanager 함수 지연(p95), 오류율, 이벤트 레이트 수집
GitOps 배포 Argo CD ApplicationSet 함수별 매니페스트 자동 동기화·Self-Heal
이력 추적 & 롤백 Git Commit + Argo CD Rollback 변경·오토스케일·복구 로그 → Git 이력




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

flowchart LR
  subgraph Developer Flow
    A[개발자: 함수 코드 커밋] --> B[Git Repository]
  end

  subgraph CI Build
    B --> C[Tekton Trigger → PipelineRun]
    C --> D[Build & Test Container]
    D --> E[Push Image to Registry]
  end

  subgraph GitOps Deploy
    B --> F[Function YAML (Knative Service)]
    F & E --> G[Argo CD ApplicationSet 감지]
    G --> H[Knative Service 생성/업데이트]
  end

  subgraph Auto-Scale & Monitor
    H --> I[Prometheus Metrics Scrape]
    I --> J[Kafka/EventSource/HTTP 트리거]
    J --> K[KEDA ScaledObject scale up/down]
  end

  subgraph Self-Heal & Audit
    H --> L{故障·Drift 감지?}
    L -- yes --> M[Argo CD Self-Heal / Rollback]
    L -- no  --> N[정상 운영]
    M --> O[Git Commit 이력 기록]
  end




🧪 실전 매니페스트 예시

1) Tekton TriggerBinding & PipelineRun

apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata: name: function-build-template
spec:
  params:
    - name: git-repo-url
  resourcetemplates:
    - apiVersion: tekton.dev/v1beta1
      kind: PipelineRun
      metadata:
        generateName: function-build-
      spec:
        pipelineRef: { name: function-build-pipeline }
        params:
          - name: repo-url
            value: "$(tt.params.git-repo-url)"

apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata: name: function-build-pipeline
spec:
  params:
    - name: repo-url
  tasks:
    - name: git-clone
      taskRef: { name: git-clone }
      params:
        - name: url
          value: "$(params.repo-url)"
    - name: build-image
      taskRef: { name: buildah }
      params:
        - name: IMAGE
          value: registry.example.com/functions/$(tasks.git-clone.results.repoName):$(tasks.git-clone.results.revision)




2) Knative Service 선언

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: {{repoName}}
  namespace: functions
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/class: keda.autoscaling.knative.dev
    spec:
      containers:
        - image: registry.example.com/functions/{{repoName}}:$(gitRevision)
          env:
            - name: TARGET
              value: "function"




3) KEDA ScaledObject (HTTP Requests)

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: {{repoName}}-http-scale
  namespace: functions
spec:
  scaleTargetRef: { name: {{repoName}}-deployment }
  minReplicaCount: 0
  maxReplicaCount: 10
  triggers:
    - type: prometheus
      metadata:
        serverAddress: http://prometheus.monitoring.svc:9090
        query: |
          sum(rate(istio_requests_total{destination_service=~"{{repoName}}\\.default\\.svc\\.cluster\\.local"}[2m]))
        threshold: "5"




4) Argo CD ApplicationSet

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata: name: functions-apps
spec:
  generators:
    - git:
        repoURL: https://github.com/org/functions-repos
        directory:
          recurse: false
          path: '*'
  template:
    metadata:
      name: '{{path.basename}}-fn'
    spec:
      project: functions
      source:
        repoURL: https://github.com/org/functions-repos
        path: '{{path.basename}}/knative'
      destination:
        namespace: functions
        server: https://kubernetes.default.svc
      syncPolicy:
        automated:
          prune: true
          selfHeal: true




✅ 기대 효과
• 개발자 경험(DevX) 향상: 함수 코드만 커밋 → 완전 서버리스 배포
• 비용 최적화: 요청이 없으면 0 → 필요한 만큼만 오토스케일
• GitOps 일관성: 매니페스트·파이프라인·오토스케일 정책을 모두 코드 선언
• 자가 치유: Drift·장애 감지 시 Argo CD가 자동 롤백·복구
• 모니터링 통합: Prometheus + KEDA로 가시적 오토스케일 제어