我的Kubernetes服务不连接到Docker容器上的RabbitMQ
我正在使用Kubernetes开发一个简单的微服务应用程序。我使用Skaffold进行开发和生产。我提供与RabbitMQ的服务之间的沟通。
当我在本地运行Kubernetes服务(即无需Kubernetes)时,我可以连接到Docker容器。但是,当我通过Kubernetes运行应用程序时,我无法连接到Docker容器。
我手动尝试时使用的URL是: BROKER_URI=amqp://127.0.0.1:15672
As I said above url works manually but not with kubernetes.它的工作也是不合逻辑的,因为它的URL为127.0.0.1。因此,我在下面写了一份Rabbitmq Kubernetes服务。
我尝试使用kubernetes时使用的URL是: amqp:://backend-rabbitmq-srv:5672
// backend-rabbitmq-srv.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-rabbitmq-depl
spec:
replicas: 1
selector:
matchLabels:
app: backend-rabbitmq
template:
metadata:
labels:
app: backend-rabbitmq
spec:
containers:
- name: backend-rabbitmq
image: rabbitmq:3
---
apiVersion: v1
kind: Service
metadata:
name: backend-rabbitmq-srv
spec:
type: NodePort
selector:
app: backend-rabbitmq
ports:
- name: http
protocol: TCP
port: 15672
targetPort: 15672
nodePort: 31672
- name: amqp
protocol: TCP
port: 5672
targetPort: 5672
nodePort: 30672
However, I am still getting an error as below.我在哪里想念?
错误:
[is-chat] OperationalError: connect ECONNREFUSED
10.104.248.71:5672
[is-chat] at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16) {
[is-chat] cause: Error: connect ECONNREFUSED 10.104.248.71:5672
[is-chat] at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16) {
[is-chat] errno: -111,
[is-chat] code: 'ECONNREFUSED',
[is-chat] syscall: 'connect',
[is-chat] address: '10.104.248.71',
[is-chat] port: 5672
[is-chat] },
[is-chat] isOperational: true,
[is-chat] errno: -111,
[is-chat] code: 'ECONNREFUSED',
[is-chat] syscall: 'connect',
[is-chat] address: '10.104.248.71',
[is-chat] port: 5672
[is-chat] }
I'm developing a simple microservice application using kubernetes. I use skaffold for development and production. And I provide communication between my services with rabbitmq.
When I run my kubernetes services locally (i.e. manually without kubernetes) I can connect to my docker container. But when I run my apps through kubernetes I can't connect to my docker container.
The url I use when I try it manually is:BROKER_URI=amqp://127.0.0.1:15672
As I said above url works manually but not with kubernetes. It would also be illogical for it to work because its url is 127.0.0.1. So I wrote a rabbitmq kubernetes service like below.
The url I use when I try it kubernetes is:amqp:://backend-rabbitmq-srv:5672
// backend-rabbitmq-srv.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-rabbitmq-depl
spec:
replicas: 1
selector:
matchLabels:
app: backend-rabbitmq
template:
metadata:
labels:
app: backend-rabbitmq
spec:
containers:
- name: backend-rabbitmq
image: rabbitmq:3
---
apiVersion: v1
kind: Service
metadata:
name: backend-rabbitmq-srv
spec:
type: NodePort
selector:
app: backend-rabbitmq
ports:
- name: http
protocol: TCP
port: 15672
targetPort: 15672
nodePort: 31672
- name: amqp
protocol: TCP
port: 5672
targetPort: 5672
nodePort: 30672
However, I am still getting an error as below. Where could I be missing?
The error:
[is-chat] OperationalError: connect ECONNREFUSED
10.104.248.71:5672
[is-chat] at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16) {
[is-chat] cause: Error: connect ECONNREFUSED 10.104.248.71:5672
[is-chat] at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16) {
[is-chat] errno: -111,
[is-chat] code: 'ECONNREFUSED',
[is-chat] syscall: 'connect',
[is-chat] address: '10.104.248.71',
[is-chat] port: 5672
[is-chat] },
[is-chat] isOperational: true,
[is-chat] errno: -111,
[is-chat] code: 'ECONNREFUSED',
[is-chat] syscall: 'connect',
[is-chat] address: '10.104.248.71',
[is-chat] port: 5672
[is-chat] }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论