Istio Networking
Istio Traffic management
Istio Traffic management 조대협 (http://bcho.tistory.com) Istio의 기능중의 하나가, 들어오는 트래픽을 여러 서비스로 라우팅을 하거나, 또는 트래픽에 테스트를 위해서 인위적으로 장애를 만들어 내는 것과..
bcho.tistory.com
현재 Nginx Ingress Controller 는 ExternalIP 192.168.19.129로 서비스 되고 있고,
Istio Ingressgateway는 ExternalIP 192.168.19.128로 서비스 되고 있다.
Sample Pod 생성시 사용했던 Tomcat 서비스를 Istio Gateway를 통해 접근하도록 해보자.
먼저, Nginx Ingress Controller 를 통하도록 구성된 ingress를 삭제한다.
$ kubectl delete ingress terry-tomcat -n default
이제, Tomcat service를 외부에서 접근할 수 있는 경로가 없어졌다.
Tomcat service를 Istio IngressGateway 를 통해서 접근하도록 구성해 보자.
Istio 설치시 만들었던 bookinfo gateway의 정보를 보면,
$ kubectl get gateway -o yaml
apiVersion: v1 items: - apiVersion: networking.istio.io/v1beta1 kind: Gateway metadata: name: bookinfo-gateway namespace: default spec: selector: istio: ingressgateway servers: - hosts: - '*' port: name: http number: 80 protocol: HTTP |
hosts "*" 로 설정되어, 모든 도메인에 대해 HTTP 80port 로 들어오는 트래픽을 처리함을 알수 있다.
다음으로, VirtualService를 보면,
$ kubectl get virtualservice
NAME GATEWAYS HOSTS AGE bookinfo [bookinfo-gateway] [*] 26h |
hosts "*"로 설정되어 모든 도메인에 대해 라우팅을 하도록 되어 있는데,
이 부분을 bookinfo 샘플 예제였던 productpage 와 tomcat 서비스를 분리하도록 수정한다.
$ kubectl edit virtualservice book-info
gateways: - bookinfo-gateway hosts: - http: - match: - uri: exact: /productpage - uri: prefix: /static - uri: exact: /login - uri: exact: /logout - uri: prefix: /api/v1/products route: - destination: host: productpage port: number: 9080 |
이러면, bookinfo virtualservice는 productpage.terrycloud.com로 들어오는 요청을 productpage 서비스로 라우팅하게 된다.
이제,tomcat서비스를 위한 virtualservice를 생성해 보자.
$ vi terry-tomcat-virtualservice.yaml
apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: terry-tomcat spec: hosts: - terry-tomcat.terrycloud.com gateways: - bookinfo-gateway http: - match: - uri: exact: /sample - uri: prefix: /sample route: - destination: host: terry-tomcat port: number: 80 |
terry-tomcat virtualservice는 terry-tomcat.terrycloud.com로 들어오는 요청을 terry-tomcat 서비스로 라우팅하게 된다.
이때, tomcat pod를 살펴보면, istio proxy sidecar container가 포함된 pod로 재생성 되었다.
※ Istio 생성시 default namespace에 istio-injection=enabled 라는 label을 생성했다. 이후에 배포되는 pod에 대해 자동으로 sidecar proxy를 생성하게 된다.
※ 혹시, pending이 걸려있다면, 기존 tomcat pod를 delete 하면 정상적으로 뜰것이다.
$ kubectl get pod
NAME READY STATUS RESTARTS AGE terry-tomcat-78d9649485-xz9h9 2/2 Running 0 144m |
$ kubectl logs -f terry-tomcat-78d9649485-xz9h9
error: a container name must be specified for pod terry-tomcat-78d9649485-xz9h9, choose one of: [tomcat istio-proxy] or one of the init containers: [war istio-init] |
pod내에 컨테이너가 두개 ( tomcat, istio-proxy ) 있으므로, 각각 지정해서 로그를 본다.
$ kubectl logs -f terry-tomcat-78d9649485-xz9h9 tomcat
INFO: Starting ProtocolHandler ["http-apr-8080"] Mar 09, 2020 11:42:20 AM org.apache.catalina.startup.Catalina start INFO: Server startup in 269 ms |
$ kubectl logs -f terry-tomcat-78d9649485-xz9h9 istio-proxy
[2020-03-09T14:03:55.918Z] "GET /sample HTTP/1.1" 302 - "-" "-" 0 0 0 0 "-" "kube-probe/1.17" "134e1c0c-afe1-9a04-91ce-9eb5b456ae02" "10.32.0.1:8080" "127.0.0.1:8080" inbound|80|http|terry-tomcat.default.svc.cluster.local 127.0.0.1:33346 10.32.0.1:8080 10.32.0.2:49290 - default [2020-03-09T14:03:55.919Z] "GET /sample/ HTTP/1.1" 200 - "-" "-" 0 636 0 0 "-" "kube-probe/1.17" "b4c07087-8e17-9a4d-850f-8e9fc9d036dc" "10.32.0.1:8080" "127.0.0.1:8080" inbound|80|http|terry-tomcat.default.svc.cluster.local 127.0.0.1:33346 10.32.0.1:8080 10.32.0.2:49292 - default |
이제 구성이 완료되었으니, 제대로 잘 동작하는지 테스트 해보자.
PC의 hosts 파일에는 terry-tomcat.terrycloud.com 이 Ingress-nginx 의 ExternalIP(192.168.19.129)로 설정되어 있다.
이부분을 Istio Ingressgateway ExternalIP (192.168.19.128) 로 변경해준다.
웹브라우저에서 http://terry-tomcat.terrycloud.com/sample 로 접속한다.
Istio Ingressgateway를 통해 잘 서비스가 되는 것인지 kiali를 통해 확인해본다.
istio-ingressgateway를 통해 terry-tomcat 서비스가 호출되고, sidecar로 떠 있는 proxy도 잘 연결되고 있음을 알수있다.
※ unknown 에서 호출되는 부분은 아마도 ReadinessProbe, LivenessProbe 인거 같다.
'Kubernetes' 카테고리의 다른 글
KF Serving (1) | 2020.03.13 |
---|---|
Knative Serving (0) | 2020.03.09 |
Istio Service Mesh (0) | 2020.03.08 |
Create Sample Pod (0) | 2020.03.07 |
Helm 3 (0) | 2020.03.07 |