<p>The <code>kubectl describe service the-load-balancer</code> command returns:</p>

<pre><code>Name:                     the-load-balancer
Namespace:                default
Labels:                   app=the-app
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"the-app"},"name":"the-load-balancer","namespac...
Selector:                 app=the-app
Type:                     LoadBalancer
IP:                       10.100.129.251
LoadBalancer Ingress:     1234567-1234567890.us-west-2.elb.amazonaws.com
Port:                     the-load-balancer  15672/TCP
TargetPort:               15672/TCP
NodePort:                 the-load-balancer  30080/TCP
Endpoints:                172.31.77.44:15672
Session Affinity:         None
External Traffic Policy:  Cluster
</code></pre>

<p>The RabbitMQ server that runs on another container, behind of load balancer is reachable from another container via the load balancer's <code>Endpoints 172.31.77.44:15672</code>.</p>

<p>But it fails to connect using <code>the-load-balancer</code> hostname or via its local <code>10.100.129.251</code> IP address. </p>

<p>What needs to be done in order to make the RabbitMQ service reachable via the load balancer's <code>the-load-balancer</code> hostname?</p>

<h1>Edited later:</h1>

<p>Running a simple Python test from another container:</p>

<pre><code>import socket
print(socket.gethostbyname('the-load-balancer'))
</code></pre>

<p>returns a load balancer local IP <code>10.100.129.251</code>.</p>

<p>Connecting to RabbitMQ using '172.31.18.32' works well:</p>

<pre><code>import pika
credentials = pika.PlainCredentials('guest', 'guest')
parameters = pika.ConnectionParameters(host='172.31.18.32', port=5672, credentials=credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
print('...channel: %s' % channel)
</code></pre>

<p>But after replacing the <code>host='172.31.18.32'</code> with <code>host='the-load-balancer'</code> or <code>host='10.100.129.251'</code> and the client fails to connect.</p>

<p>When serving <strong>RabbitMQ</strong> from behind the Load Balancer you will need to open the ports <strong>5672</strong> and <strong>15672</strong>. When configured properly the <code>kubectl describe service the-load-balancer</code> command should return both ports mapped to a local IP address:</p>

<pre><code>Name:                     the-load-balancer
Namespace:                default
Labels:                   app=the-app
Selector:                 app=the-app
Type:                     LoadBalancer
IP:                       10.100.129.251
LoadBalancer Ingress:     123456789-987654321.us-west-2.elb.amazonaws.com

Port:                     the-load-balancer-port-15672  15672/TCP
TargetPort:               15672/TCP
NodePort:                 the-load-balancer-port-15672  30080/TCP
Endpoints:                172.31.18.32:15672

Port:                     the-load-balancer-port-5672  5672/TCP
TargetPort:               5672/TCP
NodePort:                 the-load-balancer-port-5672  30081/TCP
Endpoints:                172.31.18.32:5672
</code></pre>

<p>Below is the <code>the-load-balancer.yaml</code> file used to create RabbitMQ service:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: the-load-balancer
  labels:
    app: the-app
spec:
  type: LoadBalancer
  ports:
  - port: 15672
    nodePort: 30080
    protocol: TCP
    name: the-load-balancer-port-15672 
  - port: 5672
    nodePort: 30081
    protocol: TCP
    name: the-load-balancer-port-5672   
  selector:
    app: the-app
</code></pre>
