0

我有一个部署了rabbitmq 的kubernetes 集群。我想以可以在浏览器中访问它的方式公开rabbitmanagment UI。为此,我有一个部署、服务和入口文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: rabbitmq
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rabbitmq
  template:
    metadata:
      labels:
        app: rabbitmq
    spec:
      containers:
        - image: rabbitmq:3.8.9-management
          name: rabbitmq
          ports:
            - containerPort: 5672
            - containerPort: 15672
          resources: {}
      restartPolicy: Always

服务:

apiVersion: v1
kind: Service
metadata:
  name: rabbitmq
spec:
  ports:
    - name: "5672"
      port: 5672
      targetPort: 5672
    - name: "15672"
      port: 15672
      targetPort: 15672
  selector:
    app: rabbitmq

入口文件

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
spec:
  rules: 
  - http:
      paths:
      - path: /rabbitmq
        pathType: Prefix
        backend:
          service:
            name: rabbitmq
            port:
              number: 15672

当我在浏览器中输入 http://localhost/rabbitmq 时,我收到了这个 nginx 错误:{"error":"Object Not Found","re​​ason":"Not Found"}

但是当我进入其他一些 pod 并输入: curl http://rabbitmq:15672 它得到网站的响应。

我是 kubernetes 的新手,我还没有找到任何相关的解决方案来解决我的问题,如果有人可以帮助我,我将不胜感激!!

谢谢阅读。

4

1 回答 1

0

尝试:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  ingressClassName: nginx  # <-- assumed you only have 1 ingress-nginx
  rules: 
  - http:
      paths:
      - path: /rabbitmq(/|$)(.*)
        ...

请求http://localhost/rabbitmq将被您的rabbitmq服务视为/

于 2022-02-11T11:46:41.913 回答