DevOps

[Istio] 결함 주입 (Fault Injection)

KIM DEON 2024. 1. 31. 00:47
이전 글을 참고하면 좋습니다. [DevOps] - [Istio] 트래픽 관리

결함주입

https://istio.io/latest/docs/tasks/traffic-management/fault-injection/

 

Fault Injection

This task shows you how to inject faults to test the resiliency of your application.

istio.io

istio를 통해 시스템에 의도적으로 결함을 주입 할 수 있다. 예를 들어, 요청에 시간 지연을 추가하여, 서비스를 천천히 실행시키는 것이다. 우리는 분산 시스템이 내결함성을 갖도록 구축해야한다. 시스템 신뢰를 위해 사전에 결함 테스트를 진행할 수 있다.

 

예를 들어, 외부에서 데이터를 가져오는 마이크로서비스가 존재한다. 해당 마이크로서비스에 문제가 생기면, placeholder로 그 데이터 자리를 대체하고 싶다. 이때 해당 마이크로서비스에 delay라는 결함을 주입하여, 서비스의 동작이 지연되어도 placeholder로 잘 대체가 되는지 테스트해볼 수 있다.

 

아래와 같이 설정하면, test-service 가 503을 발생시키는 결함을 주입할 수 있다.

apiVersion: networking.istio.io/v1alpha3
metadata:
  name: test-service
  namespace: default
spec:
  hosts:
    - test-service
  http:
    - fault:
        abort:
          httpStatus: 503
          percentage:
            value: 100
      route:
        - destination:
            host: test-service

 

아래는 위에서 말한 예시를 테스트할 수 있도록, 카나리 설정 후 risky 버전에 대해서 10초의 지연이 발생하도록 설정한 내용이다.

kind: VirtualService
apiVersion: networking.istio.io/v1alpha3
metadata:
  name: data-service
  namespace: default
spec:
  hosts:
    - data-service
  http:
    - match:
        - headers:
            x-my-header:
              exact: canary
      fault:
        delay:
          percentage:
            value: 100.0
          fixedDelay: 10s
      route:
        - destination:
            host: data-service
            subset: risky
    - route:
        - destination:
            host: data-service
            subset: safe
---
kind: DestinationRule
apiVersion: networking.istio.io/v1alpha3
metadata:
  name: data-service
  namespace: default
spec:
  host: data-service
  subsets:
    - labels:
        version: safe
      name: safe
    - labels:
        version: risky
      name: risky