istio 트래픽 라우팅 하기

알파로그·2023년 7월 24일
0

Kubernetes

목록 보기
15/15

✏️ Istio 의 트래픽 관리 기능

  • istio 는 kubernetes 의 service 와 비슷한 방식으로 다양한 타입으로 트래픽을 관리할 수 있다.
    • envoy 를 사용한 sidecar 가 적용된 pod 의 트래픽을 관리하는 방식이다.
      • 실제로 별도 pods 를 실행시키는 것이 아닌 ingress gateway 의 envoy 설정을 변경하는 방식으로 작동된다.
    • 순수한 k8s 의 기능을 사용한다면 ingress , deployment 까지 사용하지만,
      istio 를 적용하면 gateway , virtualService, destinationRule 을 추가로 다룰 수 있게 된다.

📍 Gateway

  • 가장 기본적인 kind 로 istio 서비스 메쉬로 유입되는 관문을 뜻한다.
    • 노출되는 port, 프로토콜, host, TLS 정보를 담고 있다.
  • 아래는 gateway 를 생성하는 기본적인 설정파일이다.
    • kubectl apply 명령어로 실행시킬 수 있다.
    • 외부 → 내부 접속이 필요하므로 ingress gateway 에서 실행시켜주면 된다.
    • gateway 만으로 트래픽 라우팅은 할 수 없다.
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: gt-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
    - port:
        number: 80
        name: http
        protocol: HTTP
      hosts:
        - "*"
  • 아래 명령어로 실행시킨 gateway 를 확인할 수 있다.
kubectl get gateways.networking.istio.io
  • 어떤 pod 에 대해 gateway 가 실행중인지 확인하는 방법도 있다.
kubectl get pods --all-namespaces -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.metadata.labels.app}{"\n"}{end}' | grep ingressgateway

📍 Virtual Service

  • Gateway 의 기능 + 트래픽 라우팅과 관련된 설정이다.
    • spec.gateway 의 값으로 앞서 생성해준 gateway 의 이름을 작성해 매핑시켜줬다.
    • metch 는 라우팅 시킬 경로를 설정할 수 있다.
      • exact : 값과 정확히 매칭 되어야 하는경우
      • prefix : url 의 앞부분만 매칭되는 경우
    • route 는 연결할 대상을 지정할 수 있다.
      • host 에 라우팅 시킬 service 명을 입력해주면 된다.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: vs-gateway
spec:
  hosts:
    - "*"
  gateways:
    - gt-gateway
  http:
    - match:
        - uri:
            prefix: /
      route:
        - destination:
            host: bk-gateway.default.svc.cluster.local
            port:
              number: 9000
    - match:
        - uri:
            prefix: /
      route:
        - destination:
            host: member.default.svc.cluster.local
            port:
              number: 8081
  • 제대로 실행됬는지 확인할 수 있다.
# kubectl get virtualservices.networking.istio.io 
NAME      GATEWAYS      HOSTS   AGE
gateway   ["gateway"]   ["*"]   3m23s
  • 아래 명령어로 ingress gateway 에 의한 라우트 설정을 확인할 수 있다.
    • prefix 로 지정한 url 경로 뒤에 * 이 붙은것을 확인할 수 있다.
# istioctl pc routes {ingress pod 이름}.istio-system
NAME          VHOST NAME       DOMAINS     MATCH                  VIRTUAL SERVICE
http.8080     blackhole:80     *           /*                     404
              backend          *           /stats/prometheus*     
              backend          *           /healthz/ready*
profile
잘못된 내용 PR 환영

0개의 댓글