ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • istio를 이용해서 클러스터 외부에서 내부로 접근하도록 설정해보기
    Envoy & Istio 2019. 8. 26. 09:00
    반응형

    istio를 설정하기 위해서 istio용으로 만들어둔 CRD를 사용한다. 

    이 중에서 이번에 Gateway와 VirtualService가 필요하다.

     

    istio에서 트래픽 라우팅을 조절하기 위해서는 VirtualService를 사용한다. 아래 내용 참조.

    자세한 내용은 https://istio.io/docs/reference/config/networking/v1alpha3/virtual-service/ 에 있음.

    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: test-route
    spec:
      hosts:
      - "*"
      gateways:
      - my-gateway
      http:
      - match:
        - uri:
            prefix: "/"
        route:
        - destination:
            host: nginx.default.svc.cluster.local

     

    hosts로 지정된 곳으로 오는 트래픽을 http나 tcp등 지정된 조건에 맞을 경우 route에 설정된 destination으로 보내는 역할을 한다.

    spec.gateways를 보면 이 virtualservice가 어떤 gateway와 연결되어 있는지 나온다. http 하위에는 어떤 url로 접근했을때 트래픽을 어디로 보내는지를 설정할 수 있는데 여기선 “/“로 접근했을때 nginx.default.svc.cluster.local 로 연결되도록 설정되어 있다.

     

    Gateway는 서비스메쉬의 내외부로 드나드는 HTTP/TCP 트래픽의 수문장 역할을 한다.

    Gateway 예제는 다음과 같다.

    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: my-gateway
      namespace: default
    spec:
      selector:
        app: istio-ingressgateway
      servers:
      - port:
          number: 80
          name: http
          protocol: HTTP
        hosts:
        - "*"

     

    spec.selector를 보면 어떤 앱이랑 연결할지를 설정한 부분이 나온다. app이 istio-ingressgateway라는 앱과 연결되어 있다는걸 확인할 수 있다.

    어떤 앱이 이 값을 가졌는지 확인해 보면 istio-ingressgateway라는 앱이 실행중인걸 볼 수 있다.

    $ kubectl get pods --all-namespaces -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.metadata.labels.app}{"\n"}{end}' | grep ingressgateway
    istio-ingressgateway-7fbf7bcf45-vrmp5    istio-ingressgateway

     

    테스트용 디플로이먼트와 서비스를 생성

    kubectl run nginx --image=nginx --port=80
    kubectl expose deploy nginx --port 30080 --target-port 80

     

    ingressgateway 컨트롤러의 ip를 확인

    kubectl get svc istio-ingressgateway -n istio-system
    NAME                   TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                                                                                      AGE
    istio-ingressgateway   LoadBalancer   10.102.123.254   localhost     15020:32186/TCP,80:31380/TCP,443:31390/TCP,31400:31400/TCP,15029:30742/TCP,15030:30721/TCP,15031:32150/TCP,15032:31170/TCP,15443:32300/TCP   7d3h

     

    클러스터 내부에서 ingressgateway쪽으로 접근해보기

    kubectl run -it --image=nicolaka/netshoot test bash
    bash-5.0# curl 10.102.123.254
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    <style>
        body {
            width: 35em;
            margin: 0 auto;
            font-family: Tahoma, Verdana, Arial, sans-serif;
        }
    </style>
    </head>
    <body>
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
    
    
    <p>For online documentation and support please refer to
    <a href="http://nginx.org/">nginx.org</a>.<br/>
    Commercial support is available at
    <a href="http://nginx.com/">nginx.com</a>.</p>
    
    
    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>
    bash-5.0#

     

    nginx 초기 화면이 나오는걸 확인할 수 있음.

     

    ingressgateway 서비스가 LoadBalancer기 때문에 클러스터 외부에서는 이 IP로 접근하면됨.

    docker for desktop 으로 설치된 경우 접근주소를 localhost로 사용하면 됨.

     

    트래픽이 외부에서 어떻게 전달되는지 확인

    istio-system 네임스페이스에 있는 istio-ingressgateway 서비스를 통해서 클러스터 내부로 트래픽이 전달되는 구조다.

    istio-ingressgateway 서비스는 istio-ingressgateway pod와 연결되어 있다.

    kubectl get svc -n istio-system
    istio-ingressgateway     LoadBalancer   10.102.123.254   localhost     15020:32186/TCP,80:31380/TCP,443:31390/TCP,31400:31400/TCP,15029:30742/TCP,15030:30721/TCP,15031:32150/TCP,15032:31170/TCP,15443:32300/TCP   7d18h

     

    istio-ingressgateway pod에 접속해서 프로세스를 확인해 보면 pilot-agent와 envoy가 함께 떠 있다.

    kubectl exec -n istio-system -it istio-ingressgateway-7fbf7bcf45-vrmp5 bash
    root@istio-ingressgateway-7fbf7bcf45-vrmp5:/# ps -ef
    UID        PID  PPID  C STIME TTY          TIME CMD
    root         1     0  0 Jun03 ?        00:00:21 /usr/local/bin/pilot-agent proxy router --domain istio-system.svc.cluster.local --log_output_level=default:info --drainDuration 45s --parentShutdownDuration 1m0s --connectTimeout 10s --serviceCluster istio-ingressgateway --zipkinAddre
    root        34     1  0 Jun03 ?        00:02:16 /usr/local/bin/envoy -c /etc/istio/proxy/envoy-rev1.json --restart-epoch 1 --drain-time-s 45 --parent-shutdown-time-s 60 --service-cluster istio-ingressgateway --service-node router~10.1.0.136~istio-ingressgateway-7fbf7bcf45-vrmp5.ist
    root        76     0  0 00:26 pts/0    00:00:00 bash
    root        85    76  0 00:26 pts/0    00:00:00 ps -ef

     

    pilot-agent가 proxy모드로 실행중이다.

     

    참조

    https://istio.io/docs/reference/config/networking/v1alpha3/gateway/

    https://istio.io/docs/reference/config/networking/v1alpha3/virtual-service/

    https://istio.io/docs/reference/commands/pilot-agent/

    반응형

    'Envoy & Istio' 카테고리의 다른 글

    envoy 환경설정하기  (0) 2020.03.27
    envoy 기본 개념  (0) 2020.03.25
    istio 현재 설정 내용 확인하기  (0) 2019.08.23
    istio ControlZ 웹 화면보기  (0) 2019.08.21
    istio 설치하기  (2) 2019.08.19

    댓글

Designed by Tistory.