<p>I have deployed two namespace in the kubernetes cluster. The namespace A host mysql and namespace B run postgress and expose their service deployment on these ports </p>

<pre><code>Namespace(A) - mysql - port (3306)
Namespace(B) - postgress - port (5432)
</code></pre>

<p>I need to use nginx-ingress kubernetes cluster to route the traffic based, here is the sample YAML file for the ingress  </p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: mysql-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: mysql-ingress
    http:
      paths:
      - path: /mysql
        backend:
          serviceName: mysql
          servicePort: 3306
</code></pre>

<p>This YAML file is more suitable for HTTP kind of service, How to achieve the TCP service using nginx-ingress</p>

<p>You can refer to the following document to expose tcp and udp services.</p>

<p><a href="https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/exposing-tcp-udp-services.md" rel="noreferrer">https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/exposing-tcp-udp-services.md</a></p>

<p>In my cluster, the ingress controller is installed on ingress-nginx namespace. You can get the tcp service from configmap.</p>

<p>kubectl get cm -n ingress-nginx tcp-services -o yaml</p>

<p>Basically, you just specify the service for your two databases.</p>

<pre><code>data:
  "3306": NamespaceA/mysql:3306
  "5432": NamespaceB/postgress:5432
</code></pre>
