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

Experiment CRD

원문 보기 위키 갱신

Experiment CRD를 사용하면 하나 이상의 ReplicaSet을 임시로 실행할 수 있어요.

출처: 문서

본문

Experiment CRD란 무엇인가요?

Experiment CRD를 사용하면 하나 이상의 ReplicaSet을 임시로 실행할 수 있어요. 임시 ReplicaSet 실행에 더해, Experiment CRD는 ReplicaSet과 함께 AnalysisRun도 실행할 수 있어요. 일반적으로 그런 AnalysisRun은 새 ReplicaSet이 예상대로 실행되고 있는지 확인하는 데 사용돼요.

가중치(weight, 트래픽 라우팅이 필요함)가 설정되거나 해당 실험에 대한 Service 속성이 설정되면, Experiment ReplicaSet으로 트래픽을 보내는 Service도 생성돼요.

Experiment의 사용 사례

  • 사용자가 특정 기간 동안 애플리케이션의 두 버전을 실행해서 애플리케이션에 대해 Kayenta 방식의 분석을 하고 싶어해요. Experiment CRD는 Experiment의 spec.templates 필드를 기반으로 2개의 ReplicaSet(baseline과 canary)을 만들고 둘 다 정상이 될 때까지 기다려요. 기간이 지나면 Experiment는 ReplicaSet을 스케일 다운하고, 사용자는 Kayenta 분석 실행을 시작할 수 있어요.

  • 사용자는 실험을 사용하여 오랜 기간 동안 애플리케이션의 다른 버전으로 여러 Experiment를 실행해서 A/B/C 테스트를 활성화할 수 있어요. 각 Experiment는 사용자가 실행하고 싶은 특정 버전을 정의하는 하나의 PodSpec 템플릿을 가져요. Experiment는 사용자가 여러 Experiment를 동시에 실행하고 각 Experiment를 자체적으로 독립되게 유지할 수 있게 해줘요.

  • 기존 애플리케이션의 새 버전을 다른 라벨로 실행해서 Kubernetes 서비스로부터 트래픽을 받지 않게 할 수 있어요. 사용자는 Rollout을 계속하기 전에 새 버전에 대해 테스트를 실행할 수 있어요.

Experiment 스펙 (Experiment Spec)

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

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 수명 주기 (Experiment Lifecycle)

Experiment는 하나 이상의 템플릿을 임시로 실행하기 위한 것이에요. Experiment의 수명 주기는 다음과 같아요.

  • spec.templates 아래에 지정된 각 파드 템플릿에 대해 ReplicaSet을 만들고 스케일해요. 파드 템플릿 아래에 service가 지정되어 있으면 그 파드에 대한 Service도 생성돼요.

  • 모든 ReplicaSet이 완전히 사용 가능해질 때까지 기다려요. 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는 그 AnalysisRun이 완료될 때까지, Experiment 기간을 초과하더라도 완료되지 않아요.

  • spec.duration도 requiredForCompletion: true도 지정되지 않으면, Experiment는 명시적으로 종료될 때까지(spec.terminate: true 설정) 무기한 실행돼요.

  • Experiment가 완료되면 ReplicaSet이 0으로 스케일되고, 완료되지 않은 AnalysisRun은 종료돼요.

참고

ReplicaSet 이름은 Experiment 이름과 템플릿 이름을 결합해서 생성돼요.

Rollouts와의 통합 (Integration With Rollouts)

Canary 전략을 사용하는 롤아웃은 experiment 스텝을 사용해서 실험을 만들 수 있어요. 실험 스텝은 Rollout에 대한 차단(blocking) 스텝 역할을 하며, Experiment가 성공할 때까지 Rollout은 계속되지 않아요. Rollout은 Rollout의 experiment 스텝에 있는 구성으로 Experiment를 만들어요. Experiment가 실패하거나 오류가 나면 Rollout은 중단돼요.

참고

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 세부 정보가 제공돼요.

참고

Experiment가 만든 baseline/canary ReplicaSet의 pod-hash는 Rollout이 만든 stable/canary ReplicaSet의 pod-hash와 다른 값을 가져요. PodSpec이 동일함에도 그렇지요. 이는 의도된 동작이에요. Experiment 파드의 메트릭이 Rollout 파드의 메트릭과 분리되어 별도로 조회될 수 있도록 하기 위해서예요.

트래픽 라우팅을 사용한 가중치 실험 스텝 (Weighted Experiment Step with Traffic Routing)

중요 — v1.1부터 사용할 수 있어요.

Canary 전략과 함께 Traffic Routing을 사용하는 Rollout은 실험 스택으로 트래픽을 세밀하게 분할할 수 있어요. Traffic Routing이 활성화되면, Rollout Experiment 스텝은 트래픽을 실험 파드로 이동시킬 수 있어요.

참고

이 기능은 현재 SMI, ALB, Istio Traffic Router에서만 사용할 수 있어요.

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 대 canary 실험을 시작해요. 파드가 준비되면(Experiment가 Running 단계에 진입하면), 롤아웃은 트래픽의 5%를 experiment-canary로, 5%를 experiment-baseline으로 보내고, 나머지 90%의 트래픽은 이전 스택으로 유지돼요.

참고

트래픽 라우팅이 있는 가중치 실험 스텝을 사용하면, 각 실험 템플릿에 대해 서비스가 자동으로 생성돼요. 트래픽 라우터는 이 서비스를 사용해 실험 파드로 트래픽을 보내요.

기본적으로 생성된 Service는 ReplicaSet의 이름을 갖고, specRef 정의에서 포트와 셀렉터를 상속받아요. {{templates.baseline.replicaset.name}} 또는 {{templates.canary.replicaset.name}} 변수를 사용해 접근할 수 있어요.

가중치 없는 Experiment Service 생성 (Experiment Service Creation without Weight)

실험에 트래픽 라우팅을 사용하고 싶지 않지만 여전히 Service를 만들고 싶다면, 선택적 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 대 canary 실험을 시작해요. 이번에는 experiment-baseline에 대해 가중치나 롤아웃의 트래픽 라우팅을 설정하지 않았어도 서비스가 생성돼요.

더 알아보기 (Learn more)