<p>Usage of the same TCP port for Rabbitmq 5672 and transfer requests to different <code>namespaces/rabbitmq_service</code> based on the host-based routing.</p>
<p>What works:</p>
<pre class="lang-yaml prettyprint-override"><code>chart: nginx-git/ingress-nginx
version: 3.32.0
values:
  - tcp:
      5672: &quot;cust1namespace/rabbitmq:5672&quot;
</code></pre>
<p>Block reflected in nginx.conf:</p>
<pre><code>server {
    preread_by_lua_block {
        ngx.var.proxy_upstream_name=&quot;tcp-cust1namespace-services-rabbitmq-5672&quot;;
    }
    listen                  :5672;
    proxy_pass              upstream_balancer;
}
</code></pre>
<p>Note: this will transfer all the requests coming to port 5672 to <code>cust1namespace/rabbitmq:5672</code>, irrespective of the client domain name and we want host-based routing based on domain name.</p>
<p>What is expected:</p>
<pre><code>chart: nginx-git/ingress-nginx
version: 3.32.0
values:
  - tcp:
      cust1domainname:5672: &quot;cust1namespace/rabbitmq:5672&quot;
      cust2domainname:5672: &quot;cust2namespace/rabbitmq:5672&quot;
</code></pre>
<p>Error:</p>
<pre><code>Failed to render chart: exit status 1: Error: unable to build kubernetes objects from release manifest: error validating &quot;&quot;: error validating data: [ValidationError(Service.spec.ports[3].port): invalid type for io.k8s.api.core.v1.ServicePort.port: got &quot;string&quot;, expected &quot;integer&quot;, ValidationError(Service.spec.ports[4].port): invalid type for io.k8s.api.core.v1.ServicePort.port: got &quot;string&quot;, expected &quot;integer&quot;]
</code></pre>
<p>The final nginx.conf should look like:</p>
<pre><code>server {
    preread_by_lua_block {
        ngx.var.proxy_upstream_name=&quot;tcp-cust1namespace-services-rabbitmq-5672&quot;;
    }
    listen                  cust1domainname:5672;
    proxy_pass              upstream_balancer;
}
    
server {
    preread_by_lua_block {
        ngx.var.proxy_upstream_name=&quot;tcp-cust2namespace-services-rabbitmq-5672&quot;;
    }
    listen                  cust2domainname:5672;
    proxy_pass              upstream_balancer;
}
</code></pre>

mayank arora
<h2>A bit of theory</h2>
<p>Approach you're trying to implement is not possible due to network protocols implementation and difference between them.</p>
<p><code>TCP</code> protocol works on transport layer, it has source and destination IPs and ports, it does <strong>not</strong> have any hosts information within. In turn <code>HTTP</code> protocol works on application layer which seats on top of the <code>TCP</code> and it does have information about host where this request is intended to be sent.</p>
<p>Please get familiar with <a href="https://docs.oracle.com/cd/E19683-01/806-4075/ipov-10/index.html" rel="nofollow noreferrer">OSI model and protocols which works on these levels</a>. This will help to avoid any confusion why this works this way and no other.</p>
<p>Also there's a <a href="https://www.quora.com/What-is-the-difference-between-HTTP-protocol-and-TCP-protocol/answer/Daniel-Miller-7?srid=nZLo" rel="nofollow noreferrer">good answer on quora about difference between HTTP and TCP protocols</a>.</p>
<h2>Answer</h2>
<p>At this point you have two options:</p>
<ol>
<li>Use ingress to work on application layer and let it direct traffic to services based on hosts which are presented in <code>request body</code>. All traffic should go through ingress endpoint (usually it's loadbalancer which is exposed outside of the cluster).</li>
</ol>
<p>Please find examples with</p>
<ul>
<li><a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#simple-fanout" rel="nofollow noreferrer">two paths and services behind them</a></li>
<li><a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting" rel="nofollow noreferrer">two different hosts and services behind them</a></li>
</ul>
<ol start="2">
<li>Use ingress to work on transport layer and expose separate TCP ports for each service/customer. In this case traffic will be passed through ingress directly to services.</li>
</ol>
<p>Based on your example it will look like:</p>
<pre><code>chart: nginx-git/ingress-nginx
    version: 3.32.0
    values:
    - tcp:
        5672: &quot;cust1namespace/rabbitmq:5672&quot; # port 5672 for customer 1
        5673: &quot;cust2namespace/rabbitmq:5672&quot; # port 5673 for customer 2
        ...
</code></pre>
