My question is related or kinda the same as How are the various Istio Ports used?, but I will try to simplify it.
Consider that I have the following istio operator config:
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
...
spec:
...
components:
...
ingressGateways:
...
service:
- port: 80
targetPort: 8080
nodePort: 30080
name: http2
protocol: TCP
And I have an ingress already forward the traffic to the port 80.
My question is about the target port here, so the request will go through the ingress on, e.g port 80, it will go through the node nodePort, the port, then the targetPort 8080 where it will land on Istio Proxy for ingress controller.
The right configurations for gateway to mesh this request will be 80 not 8080, something like:
apiVersion: networking.istio.io/v1beta1
kind: Gateway
---
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
The question is, given that the ingressgateway receives the traffic on port 8080, how it figures out the used service port was originally 80? Note that this example works fine without any issue.
Is it like the proxy queries kube-api about what's the service port for the port number I receive the request on on based on that will decide which Gateway this request belongs to?
The incoming requests which will be coming from outside are routed to ingress gateway pod. The port and target port are related to ingress gateway service and ingress gateway pod. Please run below command to check the ingress gateway service
When an application specific gateway and virtual service object is created with particular hosts mentioned in those, its virtual service responsibility for forwarding traffic arriving at a particular host or gateway port. More details about gateway and virtualservice are their in documentation.