How to configure Kubernetes to receive TCP connections

12/6/2019

I'm running a pretty basic cluster in AKS on Azure.
I need to expose a TCP server on port 6879.
I have added the TCP port to the Loadbalancer spec:

kind: Service
metadata:
  name: ingress-nginx
  selfLink: /api/v1/namespaces/ingress-nginx/services/ingress-nginx
spec:
  externalTrafficPolicy: Local
  healthCheckNodePort: 32557
  ports:
  - name: http
    nodePort: 30731
    port: 80
    protocol: TCP
    targetPort: http
  - name: https
    nodePort: 31187
    port: 443
    protocol: TCP
    targetPort: https
  - name: tcp
    nodePort: 31197
    port: 6879
    protocol: TCP
    targetPort: 6879
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
  sessionAffinity: None
  type: LoadBalancer

Would this configuration expose port 6879 or 31197 on the public IP?
I'm thinking that I need to add a rule to the Ingress to route that traffic to the TCP server host. But my reading suggests that the Kubernetes Ingress doesn't support routing TCP traffic. What part of the docs am I missing.

-- hally9k
azure-kubernetes
kubernetes
kubernetes-ingress

1 Answer

12/6/2019

TCP\UDP is supported on nginx ingress

apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: ingress-nginx
data:
  6879: "default/example-go:8080"
  31197: "namespace/service:port"

The above example shows how to expose the service example-go running in the namespace default in the port 8080 using the port 9000 (copy paste from the linked article).

-- 4c74356b41
Source: StackOverflow