ABOUT ME

데브옵스, 쿠버네티스, 네트워크, 리눅스, 클라우드 등을 공부하고 있는 개발자 입니다

Today
Yesterday
Total
  • Istio kiali를 이용한 카나리 구성과 virtual service, destination rule 정리
    K8S 2021. 6. 21. 10:58

     

    이번 포스팅에서는 키알리를 이용해서 카나리를 구현하고 생성된 virtual service와 destination rule에 대해서 알아본다. 

     

     

    1. 키알리를 이용한 카나리 구현 

     

    다음은 Kiali dashboard를 통해서 본

    fleetman-staff-service 서비스로 들어온 트래픽을 staff-service deploylment와 

    staff-service-risky-version deployment 워크로드로 로드밸런싱하는 상황이다. 

    (staff-service-risky-version가 카나리가 된다!)

     

    (api-gateway와 Position-tracker는 무시하자)

     

     

     

    < fleetman-staff-service, staff-service, staff-service-risky-version >

    apiVersion: v1
    kind: Service
    metadata:
      name: fleetman-staff-service
    spec:
      selector:
        app: staff-service
      ports:
        - name: http
          port: 8080
      type: NodePort
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: staff-service
    spec:
      selector:
        matchLabels:
          app: staff-service
      replicas: 1
      template: # template for the pods
        metadata:
          labels:
            app: staff-service
            version: safe
        spec:
          containers:
          - image: richardchesterwood/istio-fleetman-staff-service:6-placeholder
            name: staff-service
            env:
            - name: SPRING_PROFILES_ACTIVE
              value: production-microservice
            imagePullPolicy: Always
            ports:
            - containerPort: 8080
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: staff-service-risky-version
    spec:
      selector:
        matchLabels:
          app: staff-service
      replicas: 1
      template: # template for the pods
        metadata:
          labels:
            app: staff-service
            version: risky
        spec:
          containers:
          - name: staff-service
            image: richardchesterwood/istio-fleetman-staff-service:6
            env:
            - name: SPRING_PROFILES_ACTIVE
              value: production-microservice
            imagePullPolicy: Always
            ports:
            - containerPort: 8080

     

    fleetmain-staff-service는 app: staff-service 레이블을 selecting하여

    라운드 로빈 방식으로 두 디플로이먼트에 동일한 트래픽을 보낸다. 

     

    deployment 추가적으로 version: safe와 version: risky라는 레이블이 있는데 이를 이용하여 카나리를 구현한다. 

     

     

     

    다음 키알리 대쉬보드에서 새로운 라우팅 규칙을 추가하자. 

     

     

    create weighted routing을 선택하여 트래픽을 조절할 것이다. 

     

    staff-service에는 90의 비중, staff-service-risky-version에는 10의 비중을 두고 카나리를 구현한다. 

    (여기서는 staff-service-risky-version이 카나리가 된다.)

     

     

     

    다음 커맨드를 통해 api를 호출해본다. 

    while true; do curl http://[frontend ip 주소]/api/vehicles/driver/City%20Truck; echo; sleep 0.5; done

     

     

    대략적으로 9대 1의 비율로 간다.

     

     

     

     

    키알리에서도 유사한 양상을 띤다.  

     

     

     

     

     

    2. Virtual service와 destination rule 

     

    어떻게 키알리에서 트래픽을 조절한 것일까?

     

    이는 라우팅 규칙을 추가하면서 vitual service와 Destnination rule이 생성되어 fleetman-staff-service에 적용된것이다. 

     

     

     

    < 생성된 라우팅 규칙 >

     

     

     

    다음은 키알리를 통해 생성된 virtual service와 destination rule의 yaml을 확인해보자. 

     

    < 키알리에서 생성한 Virtual service와 destination rule>

    kind: VirtualService
    apiVersion: networking.istio.io/v1alpha3
    metadata:
      name: fleetman-staff-service
      namespace: default
      selfLink: >-
        /apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices/fleetman-staff-service
      uid: 0fb0dda7-4777-42f5-b4ef-86f1bef294d1
      resourceVersion: '2471613'
      generation: 1
      creationTimestamp: '2021-06-21T01:04:25Z'
      labels:
        kiali_wizard: weighted_routing
      managedFields:
        - manager: Go-http-client
          operation: Update
          apiVersion: networking.istio.io/v1alpha3
          time: '2021-06-21T01:04:25Z'
    spec:
      hosts:
        - fleetman-staff-service.default.svc.cluster.local
      http:
        - route:
            - destination:
                host: fleetman-staff-service.default.svc.cluster.local
                subset: safe
              weight: 90
            - destination:
                host: fleetman-staff-service.default.svc.cluster.local
                subset: risky
              weight: 10

     

    kind: DestinationRule
    apiVersion: networking.istio.io/v1alpha3
    metadata:
      name: fleetman-staff-service
      namespace: default
      selfLink: >-
        /apis/networking.istio.io/v1alpha3/namespaces/default/destinationrules/fleetman-staff-service
      uid: 1a05f856-1c65-4281-bd2a-dc72a28f1a13
      resourceVersion: '2471614'
      generation: 1
      creationTimestamp: '2021-06-21T01:04:25Z'
      labels:
        kiali_wizard: weighted_routing
      managedFields:
        - manager: Go-http-client
          operation: Update
          apiVersion: networking.istio.io/v1alpha3
          time: '2021-06-21T01:04:25Z'
    spec:
      host: fleetman-staff-service.default.svc.cluster.local
      subsets:
        - labels:
            version: safe
          name: safe
        - labels:
            version: risky
          name: risky
    

     

     

     

    키알리에서 생성했으므로 virtual service와 desination rule에서 필요없는 부분을 지우고 

    각 부분이 무엇을 의미하는지 알아보자. 

     

    <Virtual service와 destination rule>

    kind: VirtualService
    apiVersion: networking.istio.io/v1alpha3
    metadata:
      name: a-set-of-routing-rules-we-can-call-this-anything  # 단지 virtualservice의 이름
      namespace: default
    spec:
      hosts:
        - fleetman-staff-service.default.svc.cluster.local  # routing rules을 적용한 k8s 서비스의 dns name
      http:
        - route:
            - destination:
                host: fleetman-staff-service.default.svc.cluster.local # 타겟 서비스 DNS name
                subset: safe-group  # DestinationRule에서 정의된 이름으로 selection 쯔음이라고 생각하자
              weight: 90
            - destination:
                host: fleetman-staff-service.default.svc.cluster.local # 타겟 서비스 DNS name
                subset: risky-group  # The name defined in the DestinationRule
              weight: 10
    ---
    kind: DestinationRule       # 포드의 레이블을 이용하여 어떤 subnet으로 구분할 것인지 결정한다. 
    apiVersion: networking.istio.io/v1alpha3
    metadata:
      name: grouping-rules-for-our-photograph-canary-release # 아무 이름이나 상관없다.
      namespace: default
    spec:
      host: fleetman-staff-service # routing rule을 정해준 서비스 dns name
      subsets:
        - labels:   # k8s의 selector다.
            version: safe # version: safe라는 레이블을 가진 포드들의 서브넷을 safe-group이라고 하겠다.  
          name: safe-group
        - labels:
            version: risky # version: risky라는 레이블을 가진 포드들의 서브넷을 risky-group이라고 하겠다.
          name: risky-group

     

    위 파일을  apply해도 잘 돌아간다. 

    반응형

    'K8S' 카테고리의 다른 글

    댓글

Designed by Tistory.