<p>(While learning Kubernetes I never really found any good resources explaining this)</p>

<p>Scenario: <br>
I own mywebsite1.com   and   mywebsite2.com  and I want to host them both inside a Kubernetes Cluster. <br><br></p>

<p>I deploy a generic cloud ingress controller according to the following website with 2 <br>kubectl apply -f &lt; url > commands.   (mandatory.yaml and generic ingress.yaml) <br>
<a href="https://kubernetes.github.io/ingress-nginx/deploy/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/deploy/</a></p>

<p>So the question is what does that architecture look like? and how does the data flow into the Cluster?</p>

<p>I convert 2 certificates to 2 .key and 2 .crt files <br>
I use those files to make 2 TLS secrets (1 for each website so they'll have HTTPS enabled) <br> <br>
I create 2 Ingress Objects:</p>
<ul>
<li><p>one that says website1.com/, points to a service called website1fe, and references website1's HTTPS/TLS certificate secret. <br> (The website1fe service only listens on port 80, and forwards traffic to pods spawned by a website1fe deployment)</p>
</li>
<li><p>the other says website2.com/, points to a service called website2fe, and references website2's HTTPS/TLS certificate secret. <br> (The website2fe service only listens on port 80, and forwards traffic to pods spawned by a website2fe deployment)</p>
</li>
</ul>
<p>I have a 3 Node Kubernetes Cluster that exists in a Private Subnet. <br>
They have IPs</p>
<pre><code> 10.1.1.10     10.1.1.11     10.1.1.12
</code></pre>
<p>When I ran the 2 <br>
kubectl apply -f &lt; url &gt; commands <br>
Those commands generated: <br></p>
<ul>
<li>A kubernetes deployment containing pods running Nginx L7 LB software, that declaratively configure themselves based on Ingress .yaml objects stored in etcd, because the nginx L7 LB pods are self configuring, they're  referred to as Ingress Controller Pods. (these nginx ingress controller pods listen on ports 80 and 443.)</li>
<li>A Kubernetes Service of type Load Balancer: Kubernetes Service of type Load Balancer, uses Nodeports behind the scenes, (NodePort is safe to use when the nodes have private IPs, the NodePorts randomly (Note: service type LB uses NodePorts behind the scenes and that will be picked randomly, and cloud APIs will automatically link the cloud LB to the correct random NodePort. Alternatively you can use service type NodePort and gain the option to explicitly pick the NodePort.) pick from the range of 30000 - 32767, but for clarity sake I'll say the NodePort service is listening on ports 30080 and 30443 of every node in the cluster), A Cloud LB gets auto provisioned and exists outside of the cluster with a public IP address(using default settings), and it auto routes traffic to the NodePort that the Ingress Controller is exposed on. (An example of traffic flow: LB:443 --&gt; NP:30443 --&gt; IngressControllerPod:443 --&gt; Grafana:3000)</li>
</ul>
<p>kubectl get svc --all-namespaces
<br> Gives the IPv4 IP address of the L4 LB (let's say it's the publicly routable IP 1.2.3.4)</p>
<p>Since I own both domains: I configure internet DNS so that website1.com and website2.com both point to 1.2.3.4</p>
<p>Note: The ingress controller is cloud provider aware so it automatically did the following reverse proxy/load balancing configuration: <br></p>
<pre><code>L4LB 1.2.3.4:80 --(LB between)--&gt; 10.1.1.10:30080, 10.1.1.11:30080, 10.1.1.12:30080
L4LB 1.2.3.4:443 --(LB between)--&gt; 10.1.1.10:30443, 10.1.1.11:30443, 10.1.1.12:30443
</code></pre>
<p>KubeProxy makes it so that requests on any node's port 30080 or 30443 get forwarded inside the cluster to the Nginx L7 LB/Ingress Controller Service, which then forwards the traffic to the L7 Nginx LB Pods. <br>
The L7 Nginx LB pods terminate* the HTTPS connection and forward traffic to website1.com and website2.com services, which are listening on unencrypted port 80. <br> (It's ok that it's unencrypted because we're in the cluster where no one would be sniffing the traffic.) (*note sometimes the Cloud LB terminates HTTPS and then forwards to ingress controller over cleartext port 80 but this isn't so bad b/c the clear text happens over private IP space) <br>
(The Nginx L7 LB knows which inner cluster service/website to forward to based on the L7(http://url) address that traffic is coming in on)</p>
<hr />
<p>Note a mistake to avoid:
Let's say that website1.com wants to access some resources that exist on website2.com</p>
<p>Well website2.com actually has 2 IP addresses and 2 DNS names.<br>
website2fe.default.svc.cluster.local   &lt;-- inner cluster resolvable DNS address <br>
website2.com  &lt;-- Externally resolving DNS address <br>
<br>
Instead of having website1 access resources via website2.com
You should have website1 access resources via website2fe.default.svc.cluster.local
(It's more efficient routing)</p>
