0

I have nginx configuration to make for rabbitmq cluster whcih has got 3 containers running inside it like rabbitmq-2A, rabbitmq-2B And rabbitmq-2C. (So the host names are confugured in docker compose like rabbitm-2A) but nginx host resolves hostnames only in lower case leter (rabbitmq-2a).

So, I can't rename host because messages are already in queue (don;t want to loose existing messages)

Docker compose file docker-compose-rabbitmq.yml

version: "3.2"

services:
  rabbitmq-2A:
    image: rabbitmq:3-management-alpine
    hostname: rabbitmq-2A

  rabbitmq-2B:
    image: rabbitmq:3-management-alpine
    hostname: rabbitmq-2B

  rabbitmq-2C:
    image: rabbitmq:3-management-alpine
    hostname: rabbitmq-2C

metricsTestA{
set $rabbitmqtest http://rabbitmq-2A;
proxy_pass $rabbitmqtest 
}

This doesn't resolve as nginx tries to resolve it like rabbitmq-2a (which obviosuly) is not a host name

Also, I have tried setting upstream

upstream backends {
    least_conn;

    server backends.example.com:8080 max_fails=3;
}

server {
    location / {
        proxy_pass http://backends;
    }
}

https://www.nginx.com/blog/dns-service-discovery-nginx-plus/ Does anyone know how to get pass this?

Nitin
  • 1
  • 4
  • You're talking about cluster and docker-compose. Can you explain your setup? – akop May 08 '23 at 09:38
  • Yeah, I am running services under docker swarm. Cluster ( in the sense rabbitmq service is running and it has 3 containers running in it rabbitmq-2A, rabbitmq-2B & rabbitmq-2C. – Nitin May 08 '23 at 21:49
  • How did you setup rabbitmq? I found a tutorial where the [hostnames manually setup](https://rokpoto.com/rabbitmq-cluster-single-docker-swarm-service/). When you built it similar, then you have also to add the IPs to `/etc/hosts`. The case dosen't matter. – akop May 09 '23 at 05:23
  • setup was through the docker-compose file. (hostname:rabbitmq-2A) – Nitin May 09 '23 at 08:39
  • Which file? I have no glass globe. :P – akop May 09 '23 at 08:54
  • we have docker compose file for each services which are running so we have docker-compose-rabbitmq.yml file which has configuration of 3 containers inside them – Nitin May 09 '23 at 10:35
  • Can you share it? – akop May 09 '23 at 11:03
  • I can't share the full. but I have updated the gist of it in the question above. – Nitin May 09 '23 at 12:52

1 Answers1

0

DNS is case insensitive (RFC 4343), so this not a problem.

I guess more, that the hostnames are not correct.
Here are some hints:

  • Is your nginx in the same namespace?
    • When not, then you need the FQDN instead of simple name. Have a look at the kubernetes-config.
  • Is nginx using the right DNS-server? Can it resolve other services?

Edit

With your latest comment, I can imagine what the problem is.

I guess that you have a StatefulSet?
Then your hostname lookes weird. It should be something like rabbitmq-2A-1 or rabbitmq-1.

StatfulSets have special behaviour according to their hostnames. Related docs: StatefulSets

akop
  • 5,981
  • 6
  • 24
  • 51
  • I know the fact that DNS is insensitive. The problem is when we set rabbitmq-2A container in the proxy pass then nginx tries to resolve this as it will say that it can't resolve it (and won't let the service up as well). However, If we pass rabbitmq cluster hostname in the nginx config then it does let it start the service. – Nitin May 08 '23 at 08:55
  • I can't change my hostnames and I am running docker under docker swarm and not under k8s cluster(which doesn't make difference according to what issue is but still pointing that) – Nitin May 08 '23 at 16:12