<p>I am moving my application from docker to kubernetes \ helm - and so far I have been successful except for setting up incoming \ outgoing connections.</p>

<p>One particular issue I am facing is that I am unable to connect to the rabbitmq instance running locally on my machine on another docker container. </p>

<pre><code>app-deployment.yaml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jks
  labels:
    app: myapp
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: myapp
    spec:
      imagePullSecrets:
      - name: ivsecret
      containers:
      - env:
        - name: JOBQUEUE
          value: jks_jobqueue
        - name: PORT
          value: "80"
        image: repo.url
        name: jks
        ports:
        - containerPort: 80
        volumeMounts:
          - name: config-vol
            mountPath: /etc/sys0
      volumes:
        - name: config-vol
          configMap:
            name: config

      restartPolicy: Always

------------

app-service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: jks
spec:
  ports:
  - name: "80"
    port: 80
    targetPort: 80
  selector:
    app: myapp
</code></pre>

<p>I see errors on my container, complaining that it is not able to connect to my machine. I tried curl from inside the container:</p>

<pre><code>curl 10.2.10.122:5672
curl: (7) Failed to connect to 10.20.11.11 port 5672: Connection timed out
</code></pre>

<p>But the same when I deploy as a docker container works fine - and I am able to connect to the rabbit mq instance running on my machine on port 5672.</p>

<p>Is there something I would need to do to set up a connection from the pod to my local machine?</p>

Chillax
<p>If I understood the setup:</p>

<ul>
<li>minikube is running on the local machine. </li>
<li>rabbitmq is running on the local machine, too, and is listening on port 5672.</li>
<li>the IP where rabbitmq is running is 10.2.10.122 .</li>
<li>an application - jks - is running on minikube.</li>
</ul>

<p>The problem is that it is not possible to connect from the jks application to rabbitmq, correct?</p>

<p>One way to make it work is to first create a <em>Service without selector</em> :</p>

<pre><code>apiVersion: "v1"
kind: "Service"
metadata:
  name: "svc-external-rabbitmq"
spec:
  ports:
  - name: "rabbitmq"
    protocol: "TCP"
    port: 5672
    targetPort: 5672
    nodePort: 0
selector: {}
</code></pre>

<p>...next, create Endpoints object for the Service:</p>

<pre><code>apiVersion: "v1"
kind: "Endpoints"
metadata:
  name: "svc-external-rabbitmq"
subsets:
  - addresses:
    - ip: "10.2.10.122"
    ports:
    - name: "rabbitmq"
      port: 5672
</code></pre>

<p>...then use the service name - <code>svc-external-rabbitmq</code> - in the jks application to connect to rabbitmq.</p>

<p>For an explanation, see <a href="https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors" rel="nofollow noreferrer">Services without selectors</a> in the Kubernetes documentation. I've used this setup with a Cassandra cluster where the Cassandra nodes' IPs were all listed as <code>addresses</code>.</p>

<p>EDIT: Notice that in some cases a Service of type <a href="https://kubernetes.io/docs/concepts/services-networking/service/#externalname" rel="nofollow noreferrer">ExternalName</a> could work, too.</p>
