Kubernetes Pod无法连接到本地运行的Rabbit MQ实例 [英] Kubernetes pod unable to connect to rabbit mq instance running locally

查看:77
本文介绍了Kubernetes Pod无法连接到本地运行的Rabbit MQ实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将应用程序从docker迁移到kubernetes \ helm-到目前为止,除了设置传入\传出连接之外,我都已经成功了.

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

我面临的一个特殊问题是,我无法连接到在另一个Docker容器上的计算机上本地运行的Rabbitmq实例.

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.

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

我在我的容器上看到错误,抱怨它无法连接到我的机器.我尝试从容器内部卷曲:

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

curl 10.2.10.122:5672
curl: (7) Failed to connect to 10.20.11.11 port 5672: Connection timed out

但是当我作为docker容器部署时也可以正常工作-并且我能够在端口5672上连接到在我的机器上运行的Rabbit mq实例.

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.

我需要做些什么来建立从Pod到我的本地计算机的连接吗?

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

推荐答案

您要同时公开Pod和服务的端口80.然后卷曲在端口5672上.

You are exposing port 80 for both, the pod and the service. Then you curl on port 5672.

或者暴露容器的端口5672并将其直接卷曲,或者暴露服务的端口5672并将端口80保持在容器上,并卷曲服务的端口5672.

Either expose port 5672 of the pod and curl it directly, or expose port 5672 of the service and keep port 80 on the pod, and curl on port 5672 of the service.

这将是如何击中豆荚的高级草图":

This would be a high level "sketch" of how to hit a pod:

you -curl-> service1(80:80) -> pod1(80)
you -curl-> service2(80:5672) -> pod2(5672)

所以说你有两个豆荚.其中一个在端口80上服务,另一个在端口5672上服务.您可以创建两个服务.他们每个人都针对一个吊舱.这些服务可以在端口80上运行,并将请求映射到Pod的端口80和5672.

So say you have two pods. One of them is serving on port 80, and the other one on port 5672. You can create two services; each of them targeting one pod. The services can be running on port 80 and map the requests to the ports 80 and 5672 of the pods.

现在,您不能提供一项服务来进行这两种转发.需要每个吊舱提供一项服务.可以是一个部署,也可以是一组Pod,但是这些Pod必须在同一端口上提供服务.

Now you can't make one service to do the both forwarding. Needs to be one service per pod. Can be a deployment, or a group of pods, but these need to be serving on the same port.

这篇关于Kubernetes Pod无法连接到本地运行的Rabbit MQ实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆