<p>I am building an application over a managed K8s cluster. I can create deployments &amp; co with NodePort. Services are then accessible via these ports. </p>

<p>Managing all the exposed services and their ports is becoming a challenge and for the HTTP traffic, I was thinking of exposing a single nginx proxy that would proxy <code>https://someservice.someurl:someport</code> to  <code>https://someservice:someport</code> and have <code>someurl</code> DNS mapped to my front-end Ubuntu IP as depicted below.</p>

<p><a href="https://i.stack.imgur.com/CiX3a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CiX3a.png" alt="enter image description here"></a></p>

<p>For the web traffic, I reckon that it should work as expected. However, I have some deployments that are accessible via ssh;  git daemon for example. With these demons I am currently doing commands like this <code>git clone ssh://git@someipsofthecluster:someport/git-server/repos/somerepos</code> and I'd like to use the same DNS name as for http traffic (i.e. <code>git clone ssh://git@someservice.someurl:someport/git-server/repos/somerepo)</code></p>

<p>I know about iptables where I can redirect traffic incoming from one port to another IP/port but I don't know how I would go about redirecting to a given machine/port with regards to the subdomain used.</p>

<p>You'll probably have to re-think how to do this as TCP load balancing or proxying based on DNS name is not really possible. More on this <a href="https://serverfault.com/questions/643131/proxying-tcp-by-hostname">here</a>. Keep in mind that HTTP is a Layer 7 protocol so the proxy can use the 'Host' header to direct requests. </p>

<p>Filtering based on hostname is also not possible with iptables. More on that <a href="https://serverfault.com/questions/482221/how-do-i-filter-incoming-connections-based-on-server-hostname-port-using-iptable">here</a>.</p>

<p>You can, however, use a Layer 4 proxy, meaning a TCP proxy but this will be based on listening on a specific TCP port. <a href="https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/" rel="nofollow noreferrer">Nginx</a> can do it or you can also use something else like <a href="http://www.haproxy.org/" rel="nofollow noreferrer">Haproxy</a>.</p>
