이번에는 Plain TCP와 Ingress Gateway 분리 방법에 대해서 알아보겠다.

 

Plane TCP

Plain TCP는 Istio의 서비스 메시에서 TCP 트래픽을 관리하고 제어하는 방법을 의미한다. database (like mysql), mq (like rabbitmq) 등을 expose 할 수 있다. 단 plain TCP를 다룰 때는 istio가 프로토콜의 종류를 알 수 없으므로 retries, circuit breaking, context를 이해해야 하는 기능들은 사용할 수 없다. 

 

ingressgateway의 tcp를 보면 아래와 같이 보인다. 31400

kubectl get svc istio-ingressgateway -n istio-system \
-o jsonpath='{.spec.ports[?(@.name=="tcp")]}'
{
"name": "tcp",
"nodePort": 31598,
"port": 31400,
"protocol": "TCP",
"targetPort": 31400
}

 

이제 테스트 tcp gateway 스펙을 적용해준다.

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: tcp-test-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 31400
name: tcp-test
protocol: TCP
hosts:
- "*"
---
kubectl get gw
NAME AGE
tcp-test-gateway 6s
test-gateway 26h

 

이제 vs를 생성해 주자.

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: tcp-test-vs
spec:
hosts:
- "*"
gateways:
- tcp-test-gateway
tcp:
- match:
- port: 31400
route:
- destination:
host: tcp-test-service
port:
number: 2701
---
kubectl get vs
NAME GATEWAYS HOSTS
tcp-test-vs ["tcp-test-gateway"] ["*"]
test-gw ["test-gateway"] ["test.io"]

 

이제 telnet으로 원격을 해보자.

telnet localhost 31400
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Welcome, you are connected to node minikube.
Running on Pod tcp-test-595845f8bf-gp6w6.
In namespace default.
Service default.
hello tcp test

 

이렇게 TCP를 연결할 수 있고 DB를 띄우고 싶다면 이렇게 진행하면 좋을 거 같다.

 

Ingress Gateway 분리

Ingress Gateway를 모든 서비스가 공유하는 것은 부하와 관리에 있어서 어려움이 있을 수 있다. 그래서 Ingress Gateway를 추가적으로 구성하는 방법을 알아보자.

 

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
name: my-gateway
namespace: default
spec:
profile: empty
values:
gateways:
istio-ingressgateway:
autoscaleEnabled: false
components:
ingressGateways:
- name: istio-ingressgateway
enabled: false
- name: my-gateway
namespace: default
enabled: true
label:
istio: my-gateway
k8s:
service:
ports:
- name: tcp
port: 31400
targetPort: 31400
---
istioctl install -y -n default -f my_gateway.yaml
---
kubectl get po
NAME READY STATUS RESTARTS AGE
my-gateway-667d6b6679-s6vxq 1/1 Running 0 90s

 

istioctl로 적용해 주면 pod로 gateway가 뜬 것을 볼 수 있다. svc를 확인해서 포트를 확인해 보자.

kubectl get svc my-gateway
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d7h
my-gateway LoadBalancer 10.109.203.138 <pending> 31400:30679/TCP 2m41s

 

이제 Gateway랑 Virtual Service만 연결해 주면 31400으로 TCP가 가능하다.