Search code examples
kubernetesrabbitmqkubernetes-ingressbitnami

Exposing RabbitMQ AMQP port using ingress nginx


After research for a few days, I assume this is the most valuable answer for now, and I was tried to find my way out from that idea, just forward tcp protocol from the port to the corresponding service. But I have no luck so far.

Any suggestions are appreciated.

Environment:

  • Ubuntu 22.04
  • K3s
  • Nginx installed, using helm, namespace ingress-nginx
  • RabbitMQ installed using bitnami chart, namespace rabbitmq
First weird behavior

After using port-forwarding to check whether we're able to connect to 5672

# Allow 5672/tcp port accessible from everywhere
ufw allow 5672/tcp

# port forwarding
kubectl port-forward rabbitmq-0 5672:5672

# Checking connection success from local
telnet localhost 5672

# Checking connection failed from any other machine
telnet <my-vps-ip> 5672

I'm sure there's no other firewall, as I only use ufw command to expose other ports, they all work fine.

Any idea ?

Forward TCP request via nginx ingress

ingress-nginx-controller deploy TCP config map added --tcp-services-configmap flag within ingress-nginx-controller deployments being added

RabbitMQ service locate

Config map added Config map with port 5672 added.

Target port added to ingress-nginx-controller deployment

Checking port 5672 was also patched within ingress-nginx-controller deployment, using command kubectl get deploy ingress-nginx-controller -n ingress-nginx -o yaml

ingress-nginx-controller ingress service updated

Checking port 5672 was also patched within ingress-nginx-controller service, using command kubectl get svc ingress-nginx-controller -n ingress-nginx -o yaml

But now, even testing locally failed by command telnet localhost 5672, which previously success using port forward.

Is that I missed something ?


Solution

  • I end up using a load balancer service for it. Here's how it does

    apiVersion: v1
    kind: Service
    metadata:
      name: amqp-expose
      namespace: rabbitmq
    spec:
      ports:
        - name: amqp
          protocol: TCP
          port: 5672
          targetPort: 5672
      selector:
        app.kubernetes.io/name: rabbitmq
        app.kubernetes.io/instance: rabbitmq
      type: LoadBalancer
      sessionAffinity: None
      externalTrafficPolicy: Cluster