<p>I'm trying to set up a few micro services in Kubernetes. Everything is working as expected, except the connection from one micro service to RabbitMQ.</p>

<p>Problem flow:</p>

<ul>
<li>.NET Core app --> rabbitmq-kubernetes-service.yml --> RabbitMQ</li>
</ul>

<p><br/>
In the .NET Core app the rabbit connection factory config looks like this:</p>

<pre><code>"RabbitMQ": {
    "Host": "rabbitmq-service",
    "Port": 7000,
    "UserName": "guest",
    "Password": "guest"
}
</code></pre>

<p>The kubernetes rabbit service looks like this:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: rabbitmq-service
spec:
  selector:
    app: rabbitmq
  ports:
    - port: 7000
      targetPort: 5672
</code></pre>

<p>As well as the rabbit deployment:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: rabbitmq
  labels:
    app: rabbitmq
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rabbitmq
  template:
    metadata:
      labels:
        app: rabbitmq
    spec:
      containers:
        - name: rabbitmq
          image: &lt;private ACR with vanilla cfg - the image is: rabbitmq:3.7.9-management-alpine&gt;
          imagePullPolicy: Always        
          resources:
            limits:
              cpu: "1"
              memory: 512Mi
            requests:
              cpu: "0.5"
          ports:
            - containerPort: 5672
</code></pre>

<p>So this setup is currently <strong>not</strong> working in k8s. Locally it works like a charm with a basic docker-compose.</p>

<p><em>However</em>, what I can do in k8s is to go from a LoadBalancer --> to the running rabbit pod and access the management GUI with these config settings.</p>

<pre>
apiVersion: v1
kind: Service
metadata:
  name: rabbitmqmanagement-loadbalancer
spec:
  type: LoadBalancer
  selector:
    app: rabbitmq
  ports:
  - port: 80
    targetPort: 15672
</pre>

<p>Where am I going wrong?</p>

<p>I'm assuming you are running the <code>.NET Core app</code> outside the Kubernetes cluster.
If this is indeed the case then you need to use <code>type: LoadBalancer</code>.</p>

<p><strong><a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer" rel="nofollow noreferrer">LoadBalancer</a></strong> is used to expose a service to the internet.</p>

<p><strong>ClusterIP</strong> exposes the service inside cluster-internal IP. So <code>Service</code> will be only accessible from within the cluster, also this is a default <code>ServiceType</code>.</p>

<p><strong><a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer">NodePort</a></strong> exposes the service on each Node's IP at a static port.</p>

<p>For more details regarding Services please check the <a href="https://kubernetes.io/docs/concepts/services-networking/service" rel="nofollow noreferrer">Kubernetes docs</a>.</p>

<p>You can if the connection is working using a python script:</p>

<pre class="lang-py prettyprint-override"><code>#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(
        pika.ConnectionParameters(host='RABBITMQ_SERVER_IP'))
channel = connection.channel()

channel.queue_declare(queue='hello')

channel.basic_publish(exchange='', routing_key='hello', body='Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close()
</code></pre>

<p>This script will try to connect <code>RABBITMQ_SERVER_IP</code> using port <code>5672</code>.</p>

<p>Script requires a library <a href="https://pika.readthedocs.io/en/stable/" rel="nofollow noreferrer"><code>pika</code></a> which can be installed using <code>pip install pika</code>.</p>
