<p>I would like to create several databases inside kubernetes, and expose them trough ingresses, similar like name based virtual hosting solutions at standard http applications (<a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting</a>).</p>
<p>The problem is, databases works with TCP protocol.</p>
<p>If I try to set up TCP loadbalancing in my ingress controller (<a href="https://github.com/kubernetes/ingress-nginx/blob/main/docs/user-guide/exposing-tcp-udp-services.md" rel="nofollow noreferrer">https://github.com/kubernetes/ingress-nginx/blob/main/docs/user-guide/exposing-tcp-udp-services.md</a>), it works but one port can be used for one database only.</p>
<pre><code>kubectl get cm -n ingress-nginx ingress-nginx-tcp -oyaml
apiVersion: v1
data:
  &quot;1521&quot;: oracle/oracle-19c-ee-svc:1521
kind: ConfigMap
metadata:
  annotations:
    meta.helm.sh/release-name: ingress-nginx
    meta.helm.sh/release-namespace: ingress-nginx
  creationTimestamp: &quot;2023-03-27T11:52:08Z&quot;
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.7.0
    helm.sh/chart: ingress-nginx-4.6.0
  name: ingress-nginx-tcp
  namespace: ingress-nginx
  resourceVersion: &quot;3997675&quot;
  uid: 7c477751-1ee1-462a-a4d6-ad78b003abf7
</code></pre>
<p>I would like to achieve name based TCP routing, similar like in the first link I posted.</p>
<p>As example:</p>
<pre><code>db1.example.com:1521 -&gt; goes to service db1
db2.example.com:1521 -&gt; goes to service db2
</code></pre>
<p>(where example.com resolved as the loadbalancer IP, service db1 and db2 are services in kubernetes connected to two different databases)</p>
<p>Have you any suggestion? Even if it only resolvable with different type of ingress controller? Or Gateway API?</p>

Miklós
<p>this is simply not possible, the way HTTP(s) does this utilizes L7 support based on HOST header and/or SNI. TCP is not capable of understanding what name you are using, cause the resolution happens on the client end, and TCP connection is established using resulting IP with no trace of what domain name was used to resolve to that IP.</p>
<p>If you absolutely have to, one way to get around this could be to use a DB proxy service to create something a bit like a DB &quot;ingress controller&quot; which could route based on the username. Ie. <code>user1@server1</code> proxies to server1 while <code>user1@server2</code> proxies to server2. You can see this utilizes a L7 characteristic of usernames being provided with a routing indicator. If that is even available for your specific DB is a diffeent question.</p>
