Ingress Exposing TCP Services

A guide explains how to expose tcp and udp services running in your cluster, through the ingress controller

Kunal Saini
Kunal Saini
June 16, 2021
4 min read

Send Transactional emails With Confidence

Our dedicated support team works around the clock because transactional emails never stop.

Free Sign UpSet up in 2 minutes . No Credit Card Required

Ingress does not support TCP or UDP services. For this reason this Ingress controller uses the flags --tcp-services-configmap and --udp-services-configmap to point to an existing config map where the key is the external port to use and the value indicates the service to expose using the format: <namespace/service name>:<service port>:[PROXY]:[PROXY].

This guide describes how it can be achieved but doing this through your deployment chart is different.

Following guide assumes you have a fresh cluster with no NGINX Ingress installed.

Install NGINX Ingress using Helm

Follwing commands will install NGINX Ingress using Helm to the default namespace where nginx is being the release name and ingress-nginx/ingress-nginx is the repo.

Install helm 3

curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash

Add Ingress repo

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

Install NGINX Ingress on default namespace

helm repo update
helm install nginx ingress-nginx/ingress-nginx

Deploy your application

Here we are going to deploy an SMTP application and it's service to 587 port as ClusterIP type and then to expose it later using our ingress. Remember to replace the <IMAGE> value below.

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: smtp-chart
  labels:
    helm.sh/chart: chart-0.10.0
    app.kubernetes.io/name: chart
    app.kubernetes.io/instance: smtp
    app.kubernetes.io/version: "0.1.0"
    app.kubernetes.io/managed-by: Helm
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: chart
      app.kubernetes.io/instance: smtp
  template:
    metadata:
      labels:
        app.kubernetes.io/name: chart
        app.kubernetes.io/instance: smtp-develop
    spec:
      imagePullSecrets:
        - name: registry-secret
      containers:
        - name: chart
          image: "<IMAGE>"
          env: 
          imagePullPolicy: 
          ports:
            - containerPort: 587
              protocol: TCP
          livenessProbe:
            tcpSocket:
              port: 587
          readinessProbe:
            tcpSocket:
              port: 587

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: smtp-chart
  labels:
    helm.sh/chart: chart-0.10.0
    app.kubernetes.io/name: chart
    app.kubernetes.io/instance: smtp
    app.kubernetes.io/version: "0.1.0"
    app.kubernetes.io/managed-by: Helm
spec:
  type: ClusterIP
  ports:
    - port: 587
      targetPort: 587
      protocol: TCP
      name: smtp
      nodePort: 
  selector:
    app.kubernetes.io/name: chart
    app.kubernetes.io/instance: smtp

Patch NGINX Ingress

Download the default values.yaml file for ingress-nginx.

change following:

tcp: {}
#  8080: "default/example-tcp-svc:9000"

to:

tcp:
  587: default/smtp-chart:587

Here default is the namespace of your TCP service or pod, and smtp-chart is the deployment name that we defined in the deployment.yaml The following command will update you nginx controller, create the required config map and update config fields:

helm upgrade --install -n default nginx ingress-nginx/ingress-nginx --values values.yaml --wait

Check NGINX Ingress service

kubectl get svc -n default
NAME                                       TYPE           CLUSTER-IP       EXTERNAL-IP             PORT(S)                                    AGE
nginx-ingress-nginx-controller             LoadBalancer   10.100.106.248   a...elb.amazonaws.com   80:30918/TCP,443:32010/TCP,587:32516/TCP   12m
nginx-ingress-nginx-controller-admission   ClusterIP      10.100.7.167     <none>                  443/TCP                                    13d

In above output ingress is listening to port 587.

That's it!

You should be able to test it via telnet your ingress load balancer or external IP.

telnet a...elb.amazonaws.com 587


Mailazy Docs

Integrate with Transactional email service in minutes

click here

Most Popular Tags

EngineeringSMTPShort ReadAPIsBest PracticesEmail SecurityEmailEmail TemplatesGolangMarketing Email



What is Mailazy?

Mailazy is a Transactional Email Platform specially built for developers which satisfies the requirement for use cases like Reset Password Emails, OTP Emails, Welcome Emails, and so on. Mailazy has built to serve their customers a high value transactional email service. Sending transactional emails shouldn’t be hard with the right transaction email service. With an email service provider or simple transactional email service like Mailazy, you can easily send and track your transactional emails. Our goal is to help you achieve high delivery rates and keep your transactional emails out of the spam folder. We are always there for whenever ypu need us.

Lets get started!

Kunal Saini

Kunal Saini

Kunal is a Lead Software Development Engineer at Mailazy. He graduated in Computer Science and considers himself a learner of life. He loves to play cricket, football and computer games.

View Profile