Question

How to expose tcp port of kubernetes-nginx-ingress in DigitalOcean managed Kubernetes

Posted October 8, 2020 283 views
NginxDigitalOcean Managed Kubernetes

I am following the below the guide

[https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/](http://)

I also have deployed the nginx-ingress in kube-system namespace . These are the yamls files applied

apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-nginx-rabbitmq
  namespace: kube-system
data:
  15672: "default/rabbitmq:15672"

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert --controller deployment -v -o DO-Kubernetes
    kompose.version: 1.21.0 (992df58d8)
  creationTimestamp: null
  labels:
    io.kompose.service: rabbitmq
  name: rabbitmq
spec:
  ports:
  - name: "15672"
    port: 15672
    targetPort: 15672
  - name: "5672"
    port: 5672
    targetPort: 5672
  selector:
    io.kompose.service: rabbitmq
status:
  loadBalancer: {}


apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{"service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protoco-nginx","app.kubernetes.io/managed-by":"Helm","app.kubernetes.io/name":"ingress-nginx","app.kubernetes.io/version":"0.35.0","helm.sh/externalTrafficPolicy":"Local","ports":[{"name":"http","port":80,"protocol":"TCP","targetPort":"http"},{"name":"https","port":443,"prrnetes.io/instance":"ingress-nginx","app.kubernetes.io/name":"ingress-nginx"},"type":"LoadBalancer"}}
    kubernetes.digitalocean.com/load-balancer-id: <id>
    service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol: "true"
  creationTimestamp: "2020-09-26T04:51:57Z"
  finalizers:
  - service.kubernetes.io/load-balancer-cleanup
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/version: 0.35.0
    helm.sh/chart: ingress-nginx-2.13.0
  name: ingress-nginx-controller
  namespace: kube-system
  resourceVersion: "11774380"
  selfLink: /api/v1/namespaces/kube-system/services/ingress-nginx-controller
  uid: <uid>
spec:
  clusterIP: 10.245.75.126
  externalTrafficPolicy: Local
  healthCheckNodePort: 30093
  ports:
  - name: http
    nodePort: 30583
    port: 80
    protocol: TCP
    targetPort: http
  - name: https
    nodePort: 30628
    port: 443
    protocol: TCP
    targetPort: https
  - name: rabbitmq-tcp-15672
    nodePort: 31555
    port: 15672
    protocol: TCP
    targetPort: 15672
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
- ip: <ip>

The service is up and I can see the starting logs of rabbitmq ....(no hits) . The tcp port is also open from the loadbalancer confirmed with nc -zv. Firefox is also giving me an error

Secure Connection failed 

ip:15672 PR_END_OF_FILE_ERROR 
14 comments
  • I have the same issue, you found any way to fix this ?

  • @kennethafreelancer
    I have my doubts whether nginx TCP port supports https protocol. However non https services are able to be exposed via nginx ingress controller without the ingress yaml.

  • @favas My case is I think my port is opened, but somehow it still cannot reach internal service, in your case is rabbitmq, I am hosting a non https service (tcp oni service)

  • @favas if I expose the tcp service using normal load balancer it will work, but not if I use ingress-nginx, the same method as you

  • Show 9 more comments

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

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]

It is also possible to use a number or the name of the port. The two last fields are optional. Adding PROXY in either or both of the two last fields we can use Proxy Protocol decoding (listen) and/or encoding (proxy_pass) in a TCP service

The next example shows how to expose the service example-go running in the namespace default in the port 8080 using the port 9000

apiVersion: v1
kind: ConfigMap
metadata:
name: tcp-services
namespace: ingress-nginx
data:
9000: “default/example-go:8080”
Since 1.9.13 NGINX provides UDP Load Balancing. The next example shows how to expose the service kube-dns running in the namespace kube-system in the port 53 using the port 53

apiVersion: v1
kind: ConfigMap
metadata:
name: udp-services
namespace: ingress-nginx
data:
53: “kube-system/kube-dns:53”
If TCP/UDP proxy support is used, then those ports need to be exposed in the Service defined for the Ingress.

apiVersion: v1
kind: Service
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
type: LoadBalancer
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
- name: https
port: 443
targetPort: 443
protocol: TCP
- name: proxied-tcp-9000
port: 9000
targetPort: 9000
protocol: TCP
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx

Submit an Answer