How to route TCP traffic from outside to a Service inside a Kubernetes cluster?

10/22/2018

I have a cluster on Azure (AKS). I am have a orientdb service

apiVersion: v1
kind: Service
metadata:
  name: orientdb
  labels:
    app: orientdb
    role: backend
spec:
  selector:
    app: orientdb
  ports:
  - protocol: TCP
    port: 2424
    name: binary
  - protocol: TCP
    port: 2480
    name: http

which I want to expose to the outside, such that an app from the internet can send TCP traffic directly to this service.

(In order to connect to orientdb you need to connect over TCP to port 2424)

I am not good in networking so this is my understanding, which might as well be wrong. I tried the following:

  1. Setting up an Ingress
    • did not work, because ingress handles http, but is not well suited for tcp.
  2. I tried to set ExternalIP field in the service config in NodePort definition
    • did not work.

So my problem is the following:
I cannot send tcp traffic to the service. Http traffic works fine.

I would really appreciate if someone would show me how to expose my service such that I can sen TCP traffic directly to my oriented service.

Thanks in advance.

-- GrimSmiler
azure-aks
kubernetes
orientdb
tcp

1 Answer

10/22/2018

You can use both the service of type Loadbalancer ( I assume AKS supports that) , or you can just use the node port.

kubectl expose deployment hello-world --type=LoadBalancer --name=my-service

kubectl get services my-service

The output is similar to this:

NAME         TYPE        CLUSTER-IP     EXTERNAL-IP      PORT(S)    AGE
my-service   ClusterIP   10.3.245.137   104.198.205.71   8080/TCP   54s

Reference here

kubectl expose usage:

Usage
$ expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP|SCTP] [--target-port=number-or-name] [--name=name] [--external-ip=external-ip-of-service] [--type=type]

You can make use of --port= 2424 --target-port= 2424 options for correct ports in the kubectl expose command above

-- Ijaz Ahmad Khan
Source: StackOverflow