setting up rabbitmq in k8s with nginx ingress controller

12/24/2019

I am trying to setup rabbitmq, deployed as a pod, in k8s cluster. Also did setup Nginx ingress controller in order to have external access for the services in the cluster by using URLs.

Here is the working config through which I am able to access the rabbitmq management console:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-gateway
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /  
spec:
  tls:
  - hosts:
    - ***ABC***.com
    secretName: gateway-tls-secret
  rules:
  - host: ***ABC***.com 
    http:
      paths:
      - backend:
          serviceName: ie-rabbitmq
          servicePort: 15672
        path: /

Logs in Nginx controller

10.202.3.59 - - [24/Dec/2019:06:59:19 +0000] "GET /api/auth HTTP/2.0" 200 57 "https://***ABC***.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36" 324 0.003 [ie-poc-ie-rabbitmq-15672] [] 10.244.5.235:15672 57 0.003 200 eed95f6d3ee6bddae7a7128b4b500152

10.202.3.59 - - [24/Dec/2019:06:59:19 +0000] "GET /js/tmpl/login.ejs?0.16274381270760774 HTTP/2.0" 200 630 "https://***ABC***.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36" 48 0.001 [ie-poc-ie-rabbitmq-15672] [] 10.244.5.235:15672 630 0.001 200 75c43c0e3e3d8de715c4ffa540a4b0a8

But when I change the backend.path to /rabbit from /, the service is not reachable.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-gateway
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /  
spec:
  tls:
  - hosts:
    - ***ABC***.com
    secretName: gateway-tls-secret
  rules:
  - host: ***ABC***.com 
    http:
      paths:
      - backend:
          serviceName: ie-rabbitmq
          servicePort: 15672
        path: /rabbit

From Nginx controller logs what I see is, for this config the request is being directed to [upstream-default-backend] 10.244.3.84:8080 but ideally it should re-direct the request to [ie-poc-ie-rabbitmq-15672] [] 10.244.5.235:15672 which is observed when the request was successful.

10.202.3.59 - - [24/Dec/2019:06:57:15 +0000] "GET /api/auth HTTP/2.0" 404 21 "https://i***ABC***.com/rabbit" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36" 57 0.001 [upstream-default-backend] [] 10.244.3.84:8080 21 0.001 404 2a1d6b6abf1b7ff03884f275c4a15c14

10.202.3.59 - - [24/Dec/2019:06:57:15 +0000] "GET /js/tmpl/login.ejs?0.4076380641124395 HTTP/2.0" 404 21 "https://***ABC***.com/rabbit" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36" 47 0.001 [upstream-default-backend] [] 10.244.3.84:8080 21 0.001 404 df534e5e9b2e5aabb9fa6bb272d4b5e9

Can someone help me to understand why the second config is not working/loading rabbitmq config?

-- Here_2_learn
kubernetes
kubernetes-ingress
nginx
rabbitmq

2 Answers

1/9/2020

Try adding the management.path_prefix = /rabbit to your Rabbitmq configmap. That fixed the issue for me.

-- Martin
Source: StackOverflow

4/20/2020

Try below the NGINX Ingress Rewrite rule, it works for me:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-gateway
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - http:
        paths:
          - backend:
              serviceName: rmq-rabbitmq-ha
              servicePort: 15672
            path: /rabbit/(.*)

And here is the screenshot:

enter image description here

By the way, if you don't need the subpath, the Ingress config file is this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-gateway
spec:
  rules:
    - http:
        paths:
          - backend:
              serviceName: rmq-rabbitmq-ha
              servicePort: 15672
            path: /
-- Yuci
Source: StackOverflow