我正在尝试在kubernetes集群中设置RabbitMQ任务队列,并且需要能够从kubernetes集群外部填充任务队列。我正在尝试使用nginx入口控制器来完成此操作。尝试从集群外部声明队列或将消息发送到现有队列时遇到错误。从集群外部在Ubuntu中使用amqp-tools cli时出现错误:
$ export BROKER_URL=amqp://<host-name>:80/rabbitmq
$ /usr/bin/amqp-declare-queue --url=$BROKER_URL -q foo -d
logging in to AMQP server: invalid AMQP data
如果从群集内的VM执行相同的操作,则可以创建消息并将消息发送到队列。我还可以从集群外部连接到RabbitMQ管理UI,但是如果尝试从UI声明队列,则会在屏幕底部显示错误Management API returned status code 405 -
。
[我正在阅读RabbitMQ'/'中的虚拟主机,因为它解析主机的方式使Nginx遇到问题,但是我对这种事情不太了解,也不知道如何解决。
对此的任何帮助将不胜感激。
我正在使用建议的清单来部署Nginx入口控制器:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.30.0/deploy/static/mandatory.yaml
RabbitMQ随此清单一起部署:
---
apiVersion: v1
kind: Namespace
metadata:
name: rabbitmq
labels:
app: rabbitmq
---
apiVersion: v1
kind: Service
metadata:
name: rabbitmq-service
namespace: rabbitmq
labels:
component: rabbitmq
spec:
type: ClusterIP
ports:
- name: amqp
port: 5672
targetPort: 5672
protocol: TCP
- name: http
port: 80
targetPort: 15672
protocol: TCP
selector:
app: taskQueue
component: rabbitmq
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: rabbit-ingress
namespace: rabbitmq
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- host: <host-name>
http:
paths:
- path: /rabbitmq/?(.*)
backend:
serviceName: rabbitmq-service
servicePort: 5672
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: rabbit-manage-ingress
namespace: rabbitmq
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- host: <host-name>
http:
paths:
- path: /rabbitmq-manage/?(.*)
backend:
serviceName: rabbitmq-service
servicePort: 80
---
apiVersion: v1
kind: ReplicationController
metadata:
labels:
app: taskQueue
component: rabbitmq
name: rabbitmq-controller
namespace: rabbitmq
spec:
replicas: 1
template:
metadata:
labels:
app: taskQueue
component: rabbitmq
spec:
containers:
- image: rabbitmq:3-management
name: rabbitmq
ports:
- containerPort: 5672
- containerPort: 15672
resources:
limits:
cpu: 100m
据我所知,RabbitMQ不提供用于交互的HTTP-API(至少不是默认值)。 NGINX-Ingress无法使用Ingress资源公开与HTTP服务不同的任何内容。 Take a look at the documentation to learn how to expose a TCP- or UDP-Based service。