<p>I'm currently learning kubernetes bases and i would like to expose a mongodb outside of my cluser. I've setting up my nginx ingress controller and followig this <a href="https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/" rel="nofollow noreferrer">doc</a> to expose plain TCP connexion.</p>
<p>This is my Ingress Service configuration :</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  annotations:
  labels:
    helm.sh/chart: ingress-nginx-4.0.15
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/version: 1.1.1
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: controller
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  type: NodePort
  ipFamilyPolicy: SingleStack
  externalIPs:
  - 172.30.63.51
  ipFamilies:
    - IPv4
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: http
      appProtocol: http
    - name: https
      port: 443
      protocol: TCP
      targetPort: https
      appProtocol: https
    - name: proxied-tcp-27017
      port: 27017
      protocol: TCP
      targetPort: 27017
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/component: controller
</code></pre>
<p>The configmap to proxy TCP connexions :</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: ingress-nginx
data:
  27017: &quot;global-stack/global-stack-mongo-svc:27017&quot;
</code></pre>
<p>My ingress conroller works well on ports 80 and 443 to expose my services but impossible for me to access to port 27017</p>
<p>Result of kubectl get svc -n ingress-nginx :</p>
<pre><code>NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP    PORT(S)                                
ingress-nginx-controller             NodePort    10.97.149.93    172.30.63.51   80:30159/TCP,443:32585/TCP,27017:30098/TCP
ingress-nginx-controller-admission   ClusterIP   10.107.33.165   &lt;none&gt;         443/TCP                                  
</code></pre>
<p>External IP is well responding to curl 172.30.63.51:80</p>
<pre><code>&lt;html&gt;
&lt;head&gt;&lt;title&gt;404 Not Found&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;center&gt;&lt;h1&gt;404 Not Found&lt;/h1&gt;&lt;/center&gt;
&lt;hr&gt;&lt;center&gt;nginx&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>But can't respond to port 27017 :</p>
<pre><code>curl: (7) Failed to connect to 172.30.63.51 port 27017: Connection refused
</code></pre>
<p>My mongo service :</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: global-stack-mongo-svc
  namespace: global-stack
  labels:
    app: global-stack-mongo-app
spec:
  type: ClusterIP
  ports:
  - name: http
    port: 27017
    protocol: TCP
    targetPort: 27017
  selector:    
    app: global-stack-mongo-app
</code></pre>
<p>The services's cluster IP is 10.244.1.57 and well responding</p>
<pre><code>&gt;&gt; curl 10.244.1.57:27017

It looks like you are trying to access MongoDB over HTTP on the native driver port.
</code></pre>
<p>If anyone could help me I would be very grateful.
Thanks</p>
<p>Guieme.</p>

Guieme
<p>After some research I solved my issue.</p>
<p>in the nginx-ingress documentation, it's not described but you need to mapp the TCP config map with the ingress-controller container with this lines into the deployment file :</p>
<pre><code>  args:
    - /nginx-ingress-controller
    - --election-id=ingress-controller-leader
    - --controller-class=k8s.io/ingress-nginx
    - --configmap=$(POD_NAMESPACE)/ingress-nginx-controller
    - --validating-webhook=:8443
    - --validating-webhook-certificate=/usr/local/certificates/cert
    - --validating-webhook-key=/usr/local/certificates/key
    - --tcp-services-configmap=ingress-nginx/tcp-services
</code></pre>
