Kubernetes load balancing rabbitmq on digital ocean

3/5/2020

I need to be able to expose my rabbitmq instance periodically to the outside world.

It's running on DigitalOcean in a kuberentes 1.16 cluster with a bunch of other services. One of the services is a web server. The load balancer on that works just fine. When I try and use the same config (with different ports obviously) for my rabbitmq, I can't get it to work.

The other services within the cluster can talk to the rabbitmq just fine. I can too, if I kubectl port-forward service/rabbitmq 5672 15672 15671 and access it locally.

If I try and access it on its public IP, the connection gets dropped instantly.

$ telnet 64.225.xx.xx 15672
Trying 64.225.xx.xx...
Connected to 64.225.xx.xx.
Escape character is '^]'.
Connection closed by foreign host.

The config in its entirety:

apiVersion: v1
kind: Service
metadata:
  name: rabbitmq
  labels:
    db: rabbitmq
spec:
  ports:
  - port: 15671
    targetPort: 15671
    name: '15671'
  - port: 15672
    targetPort: 15672
    name: http
    protocol: TCP
  - port: 5672
    targetPort: 5672
    name: '5672'
  selector:
    db: rabbitmq
  type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rabbitmq-deployment
  labels:
    db: rabbitmq
spec:
  selector:
    matchLabels:
      db: rabbitmq
  replicas: 1
  template:
    metadata:
      labels:
        db: rabbitmq
    spec:
      containers:
        - name: rabbitmq
          image: rabbitmq:3-management
          ports:
          - containerPort: 15671
          - containerPort: 15672
          - containerPort: 5672
          env:
          - name: GET_HOSTS_FROM
            value: dns
          - name: RABBITMQ_DEFAULT_USER
            value: "***"
          - name: RABBITMQ_DEFAULT_PASS
            value: "***"
          - name: RABBITMQ_DEFAULT_VHOST
            value: "/"
-- zoomix
kubernetes
rabbitmq

1 Answer

3/5/2020

So for whatever reason (am I labeling these wrong) I had success making the external config be its own service. In other words, this setup works:

apiVersion: v1
kind: Service
metadata:
  name: rabbitmq
  labels:
    db: rabbitmq-svc
spec:
  ports:
  - port: 15671
    targetPort: 15671
    name: '15671'
  - port: 15672
    targetPort: 15672
    name: '15672'
    protocol: TCP
  - port: 5672
    targetPort: 5672
    name: '5672'
  selector:
    db: rabbitmq
---
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq-external
  labels:
    svc: rabbitmq-external
spec:
  ports:
  - port: 15672
    targetPort: 15672
    name: 'http'
    protocol: TCP
  - port: 5672
    targetPort: 5672
    name: '5672'
    protocol: TCP
  selector:
    db: rabbitmq
  type: LoadBalancer
---
...

Not sure why though.

-- zoomix
Source: StackOverflow