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

Apache APISIX 트래픽 관리 (Traffic Management - Apache APISIX)

원문 보기 위키 갱신

Argo Rollouts와 함께 Apache APISIX 및 Apache APISIX Ingress Controller를 사용해 트래픽을 관리할 수 있습니다. ApisixRoute는 Apache APISIX Ingress Controller를 인그레스로 사용할 때 가중치 기반 라운드 로빈(weighted round robin) 로드 밸런싱을 지원하는 객체입니다. 본 가이드는 ApisixRoute를 가중치 기반 로드 밸런서로 사용해 Argo Rollouts와 통합하는 방법을 보여 줍니다.

출처: Argo Rollouts 문서

본문

Apache APISIX와 Apache APISIX Ingress Controller를 Argo Rollouts와 함께 사용해 트래픽을 관리할 수 있습니다.

ApisixRoute는 Apache APISIX Ingress Controller를 인그레스로 사용할 때 가중치 기반 라운드 로빈 로드 밸런싱을 지원하는 객체입니다.

이 가이드는 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 객체를 위한 서비스를 만들어야 합니다.

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의 최초 생성이든 업그레이드가 발생하지 않았으므로 복제본을 즉시 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을 업데이트하는 것은 rollout spec을 수정하고, 일반적으로 컨테이너 이미지 필드를 새 버전으로 변경한 다음 새 매니페스트에 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의 업데이트 전략에 정의된 스텝을 따라 진행합니다. 예제 롤아웃은 canary에 20% 트래픽 가중치를 설정하고, 사용자가 일시 정지를 해제/승격하도록 조치를 취할 때까지 롤아웃을 무기한 일시 정지합니다.

다음 명령으로 ApisixRoute의 백엔드 가중치를 확인할 수 있습니다.

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)