I am running two postgres DBs in pods and trying to access the pods via Istio ingressgateway (with Network Load Balancer).
i have created 2 separate gateways and Virtual services for each DB (pg3.example.com and pg4.example.com). For some reason, when I am trying to connect with hostname, it connects to same host every time.
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: postgres-gateway
namespace: istio-test
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- 'pg3.example.com'
port:
number: 5432
name: tcp-postgres
protocol: TCP
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: postgres-gateway-2
namespace: istio-test
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- 'pg4.example.com'
port:
number: 5432
name: tcp-postgres
protocol: TCP
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: postgres-vs
namespace: istio-test
spec:
hosts:
- 'pg3.example.com'
gateways:
- postgres-gateway
tcp:
- match:
- port: 5432
route:
- destination:
host: postgresql-dev
port:
number: 5432
subset: postgres-0
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: postgres-vs-2
namespace: istio-test
spec:
hosts:
- 'pg4.example.com'
gateways:
- postgres-gateway-2
tcp:
- match:
- port: 5432
route:
- destination:
host: postgresql-new-dev-istio
port:
number: 5432
subset: postgres-1
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: postgres-0
namespace: istio-test
spec:
host: postgresql-dev.istio-test.svc.cluster.local
subsets:
- labels:
app.kubernetes.io/instance: postgresql-dev
name: postgres-0
trafficPolicy:
tls:
mode: ISTIO_MUTUAL
sni: postgresql-dev.istio-test.svc.cluster.local
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: postgres-1
namespace: istio-test
spec:
host: postgresql-new-dev-istio.istio-test.svc.cluster.local
subsets:
- labels:
app.kubernetes.io/instance: postgresql-new-dev-istio
name: postgres-1
trafficPolicy:
tls:
mode: ISTIO_MUTUAL
sni: postgresql-new-dev-istio.istio-test.svc.cluster.local