<p>So I have setup my application on Google cloud using Kubernetes. I have a Pod which I want to expose out of the cluster that expects TCP requests.</p>

<p>I came to know that this is possible via <a href="https://github.com/kubernetes/ingress-nginx" rel="noreferrer" title="ingress-nginx">ingress-nginx</a> and researched about it. As mentioned in the <a href="https://github.com/kubernetes/ingress-nginx/blob/nginx-0.9.0/docs/user-guide/exposing-tcp-udp-services.md" rel="noreferrer">docs here</a>, it can be done by setting up a configMap like below:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-configmap-example
data:
  9000: "default/my-service-name:7051
</code></pre>

<p>, but it's full usage is not clearly described nor I could find a complete example in the docs properly.</p>

<p>I have installed ingress-nginx as mentioned in the <a href="https://kubernetes.github.io/ingress-nginx/deploy/" rel="noreferrer">Installation Guide</a> but I am unsure what the next steps are to expose my Pod.</p>

<p><strong>Extra Info</strong></p>

<ul>
<li>The port in the Pod that I want to expose out of cluster is <code>7051</code> </li>
<li>I have a NodePort Service that targets my Pod's port that can be used with Ingress to expose.</li>
</ul>

Ketan Saxena
<p>So, in order to achieve this you can do this:</p>

<ol>
<li>First create the configMap that you added to the post.</li>
</ol>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-configmap-example
data:
  9000: "default/my-service-name:7051
</code></pre>

<ol start="2">
<li><p>Then edit your nginx-ingress-controller deployment by adding this flag to container args like below:</p>

<pre><code>...
containers:
- name: nginx-ingress-controller
  image: "quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.26.1"
  imagePullPolicy: "IfNotPresent"
  args:
    - /nginx-ingress-controller
    - --default-backend-service=nginx-ingress/nginx-ingress-default-backend
    - --election-id=ingress-controller-leader
    - --ingress-class=nginx
    - --configmap=nginx-ingress/nginx-ingress-controller
    - --tcp-services-configmap=default/tcp-configmap-example
    ...
</code></pre></li>
<li><p>Edit LoadBalancer service by adding port to your LoadBalancer</p>

<pre><code>...
ports:
- name: http
  port: 80
  protocol: TCP
  targetPort: http
- name: https
  port: 443
  protocol: TCP
  targetPort: https
- name: some-service-port
  port: 7051
  protocol: TCP
</code></pre></li>
</ol>

<p>Hope it helps!</p>
