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

Experiment CRD

원문 보기 위키 갱신

Experiment CRD는 하나 이상의 ReplicaSet을 임시로 실행(run)하게 해주는 Argo Rollouts의 커스텀 리소스입니다. 단순히 임시 ReplicaSet을 띄우는 것에 더해, ReplicaSet과 함께 AnalysisRun을 실행할 수도 있는데, 보통 새 ReplicaSet이 기대대로 동작하는지 확인하는 데 사용합니다. 실험(Experiment) ReplicaSet으로 트래픽을 보내는 Service는, weight(트래픽 라우팅이 필요한)가 설정되었거나 해당 Experiment의 Service 속성이 설정된 경우에만 생성됩니다.

출처: Argo Rollouts 문서

본문

Experiment CRD란 무엇인가?

Experiment CRD는 사용자가 하나 이상의 ReplicaSet을 임시로 실행할 수 있게 해줍니다. 임시 ReplicaSet을 실행하는 것에 더해, Experiment CRD는 ReplicaSet과 함께 AnalysisRun을 실행할 수 있습니다. 일반적으로 이 AnalysisRun들은 새 ReplicaSet이 기대대로 동작하는지 확인하는 데 사용됩니다.

Experiment ReplicaSet으로 트래픽을 보내는 Service도, weight(트래픽 라우팅이 필요한)가 설정되었거나 해당 Experiment의 Service 속성이 설정된 경우에 생성됩니다.

Experiment의 사용 사례 (Use cases)

  • 사용자가 일정 시간 동안 애플리케이션의 두 버전을 실행해 Kayenta 방식의 분석을 수행하려는 경우. Experiment CRD는 Experiment의 spec.templates 필드에 기반해 2개의 ReplicaSet(baseline과 canary)을 만들고, 둘 다 healthy 해질 때까지 기다립니다. 시간이 지나면 Experiment가 ReplicaSet을 스케일 다운하고, 사용자는 Kayenta 분석 실행을 시작할 수 있습니다.
  • 사용자가 애플리케이션의 서로 다른 버전으로 여러 Experiment를 오래 실행해 A/B/C 테스트를 활성화하려는 경우. 각 Experiment에는 사용자가 실행하려는 특정 버전을 정의하는 PodSpec 템플릿이 하나씩 있습니다. Experiment는 사용자가 여러 Experiment를 한 번에 실행하고 각각을 독립적으로 유지할 수 있게 해줍니다.
  • 기존 애플리케이션의 새 버전을 서로 다른 레이블로 실행해 Kubernetes Service로부터 트래픽을 받지 않게 하려는 경우. 사용자는 Rollout을 계속 진행하기 전에 새 버전에 대해 테스트를 실행할 수 있습니다.

Experiment 스펙 (Spec)

아래는 각각 1개의 replica를 가진 두 ReplicaSet을 만들고, 둘 다 사용 가능해지면 20분 동안 실행하는 Experiment 예시입니다. 추가로 몇 개의 AnalysisRun을 실행해 Experiment의 파드에 대해 분석을 수행합니다.

apiVersion: argoproj.io/v1alpha1
kind: Experiment
metadata:
  name: example-experiment
spec:
  # Duration of the experiment, beginning from when all ReplicaSets became healthy (optional)
  # If omitted, will run indefinitely until terminated, or until all analyses which were marked
  # `requiredForCompletion` have completed.
  duration: 20m

  # Deadline in seconds in which a ReplicaSet should make progress towards becoming available.
  # If exceeded, the Experiment will fail.
  progressDeadlineSeconds: 30

  # List of pod template specs to run in the experiment as ReplicaSets
  templates:
  - name: purple
    # Number of replicas to run (optional). If omitted, will run a single replica
    replicas: 1
    # Flag to create Service for this Experiment (optional)
    # If omitted, a Service won't be created.
    service:
      # Name of the Service (optional). If omitted, service: {} would also be acceptable.
      name: service-name
    selector:
      matchLabels:
        app: canary-demo
        color: purple
    template:
      metadata:
        labels:
          app: canary-demo
          color: purple
      spec:
        containers:
        - name: rollouts-demo
          image: argoproj/rollouts-demo:purple
          imagePullPolicy: Always
          ports:
          - name: http
            containerPort: 8080
            protocol: TCP
  - name: orange
    replicas: 1
    minReadySeconds: 10
    selector:
      matchLabels:
        app: canary-demo
        color: orange
    template:
      metadata:
        labels:
          app: canary-demo
          color: orange
      spec:
        containers:
        - name: rollouts-demo
          image: argoproj/rollouts-demo:orange
          imagePullPolicy: Always
          ports:
          - name: http
            containerPort: 8080
            protocol: TCP

  # List of AnalysisTemplate references to perform during the experiment
  analyses:
  - name: purple
    templateName: http-benchmark
    args:
    - name: host
      value: purple
  - name: orange
    templateName: http-benchmark
    args:
    - name: host
      value: orange
  - name: compare-results
    templateName: compare
    # If requiredForCompletion is true for an analysis reference, the Experiment will not complete
    # until this analysis has completed.
    requiredForCompletion: true
    args:
    - name: host
      value: purple

Experiment 수명주기 (Lifecycle)

Experiment는 하나 이상의 템플릿을 일시적으로 실행하기 위한 것입니다. Experiment의 수명주기는 다음과 같습니다:

  • spec.templates 아래에 지정된 각 파드 템플릿에 대해 ReplicaSet을 만들고 스케일합니다. 파드 템플릿에 service가 지정되어 있으면 해당 파드를 위한 Service도 생성됩니다.
  • 모든 ReplicaSet이 완전히 사용 가능(available)해질 때까지 기다립니다. ReplicaSet이 spec.progressDeadlineSeconds 내에 사용 가능해지지 않으면 Experiment는 실패합니다. 사용 가능해지면 Experiment는 Pending 상태에서 Running 상태로 전환됩니다.
  • Experiment가 Running으로 간주되면, spec.analyses에 참조된 모든 AnalysisTemplate에 대해 AnalysisRun을 시작합니다.
  • spec.duration이 지정되어 있으면, Experiment는 시간이 경과한 후에 완료됩니다.
  • AnalysisRun이 실패하거나 오류가 나면, Experiment는 그 실패한 AnalysisRun의 상태(예: Failed 또는 Error)와 동일한 상태로 조기 종료됩니다.
  • 참조된 AnalysisTemplate 중 하나 이상이 requiredForCompletion: true로 표시되어 있으면, Experiment는 Experiment 기간을 초과하더라도 그 AnalysisRun들이 완료될 때까지 완료되지 않습니다.
  • spec.duration도 requiredForCompletion: true도 지정되지 않으면, Experiment는 명시적으로 종료될 때까지(spec.terminate: true 설정) 무기한 실행됩니다.
  • Experiment가 완료되면 ReplicaSet들은 0으로 스케일 다운되고, 완료되지 않은 AnalysisRun들은 종료됩니다.

참고 (Note)

ReplicaSet 이름은 Experiment 이름과 템플릿 이름을 결합해 생성됩니다.

Rollouts와의 통합 (Integration With Rollouts)

Canary 전략을 사용하는 롤아웃은 experiment 스텝을 사용해 Experiment를 만들 수 있습니다. experiment 스텝은 Rollout의 블로킹(차단) 스텝 역할을 하며, Experiment가 성공하기 전까지 Rollout은 계속 진행되지 않습니다. Rollout은 Rollout의 experiment 스텝에 있는 구성으로 Experiment를 만듭니다. Experiment가 실패하거나 오류가 나면 Rollout은 중단(abort)됩니다.

참고 (Note)

Experiment 이름은 Rollout 이름, 새 ReplicaSet의 PodHash, Rollout의 현재 리비전(revision), 그리고 현재 스텝 인덱스를 결합해 생성됩니다.

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: guestbook
  labels:
    app: guestbook
spec:
...
  strategy:
    canary: 
      steps:
      - experiment:
          duration: 1h
          templates:
          - name: baseline
            specRef: stable
          - name: canary
            specRef: canary
          analyses:
          - name : mann-whitney
            templateName: mann-whitney
            args:
            - name: baseline-hash
              value: "{{templates.baseline.podTemplateHash}}"
            - name: canary-hash
              value: "{{templates.canary.podTemplateHash}}"

위 예시에서, Rollout 업데이트 중 Rollout은 Experiment를 실행합니다. Experiment는 각각 1개의 replica를 가진 baseline과 canary 두 ReplicaSet을 만들고 1시간 동안 실행됩니다. baseline 템플릿은 stable ReplicaSet의 PodSpec을, canary 템플릿은 canary ReplicaSet의 PodSpec을 사용합니다.

추가로, Experiment는 mann-whitney라는 AnalysisTemplate을 사용해 분석을 수행합니다. AnalysisRun에는 각각 {{templates.baseline.podTemplateHash}}와 {{templates.canary.podTemplateHash}} 변수를 사용해 baseline과 canary의 pod-hash 세부 정보가 제공되며, 필요한 메트릭 쿼리를 수행합니다.

참고 (Note)

Experiment가 만든 baseline/canary ReplicaSet의 pod-hash는, Rollout이 만든 stable/canary ReplicaSet의 pod-hash와 값이 다릅니다. PodSpec이 같음에도 그렇습니다. 이는 의도적인 동작으로, Experiment 파드의 메트릭을 Rollout 파드의 메트릭과 별도로 구분해 쿼리할 수 있게 하기 위함입니다.

트래픽 라우팅을 사용하는 가중(Weighted) Experiment 스텝

중요 (Important)

v1.1부터 사용 가능

Canary 전략과 트래픽 라우팅을 함께 사용하는 Rollout은 experiment 스택으로 트래픽을 세밀하게 나눌 수 있습니다. 트래픽 라우팅이 활성화되면 Rollout Experiment 스텝은 experiment 파드로 트래픽을 전환(shift)시킬 수 있습니다.

참고 (Note)

이 기능은 현재 SMI, ALB, 그리고 Istio 트래픽 라우터에서만 사용할 수 있습니다.

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: guestbook
  labels:
    app: guestbook
spec:
...
strategy:
  canary:
    trafficRouting:
      alb:
        ingress: ingress
        ...
    steps:
      - experiment:
          duration: 1h
          templates:
            - name: experiment-baseline
              specRef: stable
              weight: 5
            - name: experiment-canary
              specRef: canary
              weight: 5

위 예시에서, 업데이트 중 첫 번째 스텝은 baseline vs canary experiment를 시작합니다. 파드가 준비되면(Experiment가 Running 단계에 들어가면), 롤아웃은 트래픽의 5%를 experiment-canary로, 5%를 experiment-baseline으로 보내고, 나머지 90%는 기존 스택으로 보냅니다.

참고 (Note)

트래픽 라우팅이 있는 가중 experiment 스텝을 사용하면, 각 experiment 템플릿에 대해 서비스가 자동 생성됩니다. 트래픽 라우터는 이 서비스를 사용해 experiment 파드로 트래픽을 보냅니다.

기본적으로 생성된 Service 이름은 ReplicaSet 이름이며, 포트와 셀렉터는 specRef 정의에서 상속받습니다. 각각 {{templates.baseline.replicaset.name}} 또는 {{templates.canary.replicaset.name}} 변수로 접근할 수 있습니다.

weight 없이 Experiment Service 생성하기

Experiment에 트래픽 라우팅을 사용하고 싶지 않지만 Service를 만들고 싶다면, weight를 설정하지 않고도 선택적 Name을 받는 Service 객체를 설정할 수 있습니다.

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: guestbook
  labels:
    app: guestbook
spec:
...
strategy:
  canary:
    steps:
      - experiment:
          duration: 1h
          templates:
            - name: experiment-baseline
              specRef: stable
              service:
                name: test-service
            - name: experiment-canary
              specRef: canary

위 예시에서, 업데이트 중 첫 번째 스텝은 baseline vs canary experiment를 시작합니다. 이번에는 weight나 롤아웃의 트래픽 라우팅 없이도 experiment-baseline을 위한 Service가 생성됩니다.

더 알아보기 (Learn more)

  • Rollout 전체 스펙(specification)과 필드별 옵션
  • 카나리·블루-그린 배포 전략 이해하기
  • AnalysisTemplate과 AnalysisRun을 통한 메트릭 기반 자동 판정
  • 트래픽 관리(서비스 메시, Ingress) 구성하기