Search code examples
kubernetesmqttkubernetes-ingressnginx-ingress

Kubernetes NGINX Ingŕess controller TCP / MQTT config


I have an Kubernetes Cluster with a working Ingress config for one REST API. Now I want to add a port forward to my mqtt adapter to this config, but I have problems finding a way to add an TCP rule to the config. The Kubernetes docs only show a HTTP example. https://kubernetes.io/docs/concepts/services-networking/ingress/

I'm pretty new to Kubernetes and I have problems adapting other configs, because whatever I find looks totally different from that what I found in the Kubernetes Docs.

I have used a regular nginx webserver with letsencrypt to secure TCP connections. I hope this works with the ingress controller, too.

My goal is to send messages via MQTT with TLS to my cluster. Does someone have the right docs for this or knows how to add the config?

My config looks like this:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ratings-web-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    cert-manager.io/cluster-issuer: letsencrypt
spec:
  tls:
    - hosts: 
      - example.com
      secretName: ratings-web-cert
  
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          serviceName: test-api
          servicePort: 8080
        path: /

Solution

  • the Ingress system only handles HTTP traffic in general. A few Ingress Controllers support custom extensions for non-HTTP packet handling but it's different for each. https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/ shows how to do this specifically for ingress-nginx, as shown there you configure it entirely out of band via some ConfigMaps, not via the Ingress object(s).

    What you probably actually want is a LoadBalancer type Service object instead.