본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Apache APISIX

원문 보기 위키 갱신

Apache APISIX와 Apache APISIX Ingress Controller를 Argo Rollouts과 함께 트래픽 관리에 사용할 수 있어요.

출처: 문서

본문

Apache APISIX와 Apache APISIX Ingress Controller를 Argo Rollouts과 함께 트래픽 관리에 사용할 수 있어요.

Apache APISIX Ingress Controller를 ingress로 사용할 때 가중치 기반 라운드 로빈(weighted round robin) 로드 밸런싱을 지원하는 객체가 ApisixRoute예요.

이 가이드에서는 ApisixRoute를 가중치 기반 라운드 로빈 로드 밸런서로 사용해 Argo Rollouts과 통합하는 방법을 보여줄게요.

사전 요구사항 (Prerequisites)

Argo Rollouts은 Apache APISIX v2.15 이상과 Apache APISIX Ingress Controller v1.5.0 이상이 필요해요.

Helm v3로 Apache APISIX와 Apache APISIX Ingress Controller를 설치해요.

helm repo add apisix https://charts.apiseven.com
kubectl create ns apisix

helm upgrade -i apisix apisix/apisix --version=0.11.3 \
--namespace apisix \
--set ingress-controller.enabled=true \
--set ingress-controller.config.apisix.serviceNamespace=apisix

부트스트랩 (Bootstrap)

먼저 가중치 기반 라운드 로빈 로드 밸런싱 기능을 사용해서 ApisixRoute 객체를 만들어야 해요.

apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: rollouts-apisix-route
spec:
  http:
    - name: rollouts-apisix
      match:
        paths:
          - /*
        hosts:
          - rollouts-demo.apisix.local
      backends:
        - serviceName: rollout-apisix-canary-stable
          servicePort: 80
        - serviceName: rollout-apisix-canary-canary
          servicePort: 80
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/examples/apisix/route.yaml

참고로 여기서는 weight 필드를 지정하지 않아요. 이 필드는 ArgoCD와 동기화돼야 하기 때문이에요. 이 필드를 지정하고 Argo Rollouts 컨트롤러가 그것을 바꾸면, Argo CD로 Rollout을 관리하는 경우 ArgoCD 컨트롤러가 이를 감지하고 이 리소스가 동기화되지 않았다고(out of sync) 표시할 거예요.

둘째로, Argo Rollouts 객체를 만들어야 해요.

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: rollout-apisix-canary
spec:
  replicas: 5
  strategy:
    canary:
      canaryService: rollout-apisix-canary-canary
      stableService: rollout-apisix-canary-stable
      trafficRouting:
        managedRoutes:
          - name: set-header
        apisix:
          route:
            name: rollouts-apisix-route
            rules:
              - rollouts-apisix
      steps:
        - setCanaryScale:
            replicas: 1
          setHeaderRoute:
            match:
              - headerName: trace
                headerValue:
                  exact: debug
            name: set-header
        - setWeight: 20
        - pause: {}
        - setWeight: 40
        - pause:
            duration: 15
        - setWeight: 60
        - pause:
            duration: 15
        - setWeight: 80
        - pause:
            duration: 15
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: rollout-apisix-canary
  template:
    metadata:
      labels:
        app: rollout-apisix-canary
    spec:
      containers:
        - name: rollout-apisix-canary
          image: argoproj/rollouts-demo:blue
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          resources:
            requests:
              memory: 32Mi
              cpu: 5m
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/examples/apisix/rollout.yaml

마지막으로 Argo Rollouts 객체를 위한 service들을 만들어야 해요.

apiVersion: v1
kind: Service
metadata:
  name: rollout-apisix-canary-canary
spec:
  ports:
    - port: 80
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app: rollout-apisix-canary
    # This selector will be updated with the pod-template-hash of the canary ReplicaSet. e.g.:
    # rollouts-pod-template-hash: 7bf84f9696
---
apiVersion: v1
kind: Service
metadata:
  name: rollout-apisix-canary-stable
spec:
  ports:
    - port: 80
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app: rollout-apisix-canary
    # This selector will be updated with the pod-template-hash of the stable ReplicaSet. e.g.:
    # rollouts-pod-template-hash: 789746c88d
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/examples/apisix/services.yaml

어떤 Rollout이든 최초 생성 시에는 업그레이드가 발생하지 않았으므로 replica를 즉시 100%로 스케일업해요(카나리아 업그레이드 단계, 분석 등을 건너뜀).

Argo Rollouts kubectl 플러그인을 사용하면 Rollout과 관련 리소스(ReplicaSets, Pods, AnalysisRuns)를 시각화하고, 발생하는 실시간 상태 변경을 보여줘요. 롤아웃이 배포되는 모습을 보려면 플러그인의 get rollout --watch 명령을 실행하세요.

kubectl argo rollouts get rollout rollout-apisix-canary --watch

Rollout 업데이트 (Updating a Rollout)

이제 업데이트를 수행할 차례예요. Deployment와 마찬가지로 Pod template 필드(spec.template)의 어떤 변경도 새 버전(즉 ReplicaSet)을 배포하게 만들어요. Rollout을 업데이트하는 것은 롤아웃 스펙을 수정하는 것, 보통 컨테이너 이미지 필드를 새 버전으로 바꾸고 새 매니페스트에 kubectl apply를 실행하는 것을 포함해요. 편의를 위해 rollouts 플러그인은 실행 중인 rollout 객체에 대해 이 단계들을 제자리에서 수행하는 set image 명령을 제공해요. 다음 명령은 rollout-apisix-canary Rollout을 컨테이너의 "yellow" 버전으로 업데이트해요.

kubectl argo rollouts set image rollout-apisix-canary \
  rollouts-demo=argoproj/rollouts-demo:yellow

롤아웃 업데이트 중에 컨트롤러는 Rollout의 업데이트 전략에 정의된 단계들을 진행해요. 예시 롤아웃은 카나리아에 20%의 트래픽 weight를 설정하고, 사용자가 일시중지 해제/승격(promote) 작업을 할 때까지 무기한 일시중지해요.

다음 명령으로 ApisixRoute의 backend weight를 확인할 수 있어요.

kubectl describe apisixroute rollouts-apisix-route

......
Spec:
  Http:
    Backends:
      Service Name:  rollout-apisix-canary-stable
      Service Port:  80
      Weight:        80
      Service Name:  rollout-apisix-canary-canary
      Service Port:  80
      Weight:        20
......

rollout-apisix-canary-canary 서비스는 Apache APISIX를 통해 20%의 트래픽을 받아요.

다음 명령으로 SetHeader ApisixRoute의 match를 확인할 수 있어요.

kubectl describe apisixroute set-header

......
Spec:
  Http:
    Backends:
      Service Name:  rollout-apisix-canary-canary
      Service Port:  80
      Weight:        100
    Match:
      Exprs:
        Op:  Equal
        Subject:
          Name:   trace
          Scope:  Header
        Value:    debug
......

더 알아보기 (Learn more)