A/B 테스트는 두 개 이상의 버전(예: 기존 버전과 신규 버전)을 사용자 그룹에 나누어 제공하고, 반응을 비교하여 더 나은 버전을 선택하는 전략이다. Flagger를 사용하면 쿠키나 헤더를 기반으로 트래픽을 분리하여, 실제 서비스에 무리 없이 A/B 테스트를 수행할 수 있다. 이는 Canary 배포와 달리 트래픽을 조건부로 분할하는 점이 특징이다.
helm repo add flagger https://flagger.app
helm repo update
helm upgrade -i flagger flagger/flagger \
--namespace istio-system \
--set meshProvider=istio \
--set metricsServer=http://prometheus:9090
테스트용 애플리케이션으로 podinfo를 배포한다.
kubectl create ns test
kubectl label namespace test istio-injection=enabled
helm upgrade -i podinfo flagger/podinfo \
--namespace test \
--set service.type=ClusterIP \
--set image.tag=6.0.0
A/B 테스트를 위해 Canary 리소스를 생성한다.
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
name: podinfo
namespace: test
spec:
provider: istio
targetRef:
apiVersion: apps/v1
kind: Deployment
name: podinfo
service:
port: 9898
gateways:
- istio-system/public-gateway
hosts:
- podinfo.example.com
analysis:
interval: 1m
threshold: 5
iterations: 10
match:
- headers:
cookie:
regex: "^(.*?;)?(canary=true)(;.*)?$"
metrics:
- name: request-success-rate
thresholdRange:
min: 99
interval: 1m
match 조건을 통해 쿠키가 canary=true인 요청만 새 버전으로 보내도록 설정한다.metrics를 통해 요청 성공률이 99% 이상이어야 테스트를 계속 진행하도록 설정했다.Podinfo의 새 버전을 배포한다.
kubectl set image deployment/podinfo podinfod=ghcr.io/stefanprodan/podinfo:6.0.1 -n test
Flagger는 새로운 이미지를 감지하고, 설정한 조건에 따라 일부 사용자에게만 새 버전을 서비스하기 시작한다.
쿠키가 있는 요청과 없는 요청으로 버전을 확인할 수 있다.
curl -H "cookie: canary=true" http://podinfo.example.com
curl http://podinfo.example.com
쿠키가 설정된 요청만 새 버전(v6.0.1)으로 라우팅되고, 나머지는 기존 버전(v6.0.0)으로 이동한다.
Flagger의 상태를 모니터링하며, 분석 결과를 확인한다.
watch kubectl -n test get canaries
상태가 Succeeded로 변경되면 모든 사용자에게 새 버전이 배포된다.