无法从kubernetes集群访问Rabbitmq仪表板

时间:2019-05-21 07:43:17

标签: docker kubernetes rabbitmq

kubernetes集群在两个节点上运行。一位主人,一位工人... 编织网是pod网络。

[root@irf-centos1 ~]# kubectl cluster-info
Kubernetes master is running at https://10.8.156.184:6443
KubeDNS is running at https://10.8.156.184:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

已将Rabbit docker映像作为容器部署在kubernetes pod中。

[root@irf-centos1 ~]# kubectl get pods
NAME                        READY   STATUS    RESTARTS   AGE
rabbitmq-86bd97fd9d-8h444   1/1     Running   0          51m
rabbitmq-86bd97fd9d-n2kgk   1/1     Running   0          51m

以下是服务和部署yaml文件

部署文件

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: rabbitmq
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: rabbitmqapp
    spec:
      containers:
        -
          image: "docker.io/rabbitmq:latest"
          imagePullPolicy: Always
          name: rabbitmq
          ports:
            -
              containerPort: 5672
              name: http-port
          volumeMounts:
            -
              mountPath: /var/rabbitmqapp_home
              name: rabbitmqapp-home
      volumes:
        -
          emptyDir: {}
          name: rabbitmqapp-home

服务文件

---
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq
  namespace: default
spec:
  ports:
    -
      port: 5672
      targetPort: 5672
      protocol: TCP
      nodePort: 31111
  selector:
    app: rabbitmqapp
  type: NodePort

这是服务和部署详细信息

[root@irf-centos1 ~]# kubectl get deployments
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
rabbitmq   2/2     2            2           55m


[root@irf-centos1 ~]# kubectl get services
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP          3d
rabbitmq     NodePort    10.98.204.64   <none>        5672:31111/TCP   55m

现在,当我尝试在节点端口上点击Rabbitmq仪表板/ UI时。不可访问

[root@irf-centos1 ~]# curl http://10.8.156.187:31111
curl: (56) Recv failure: Connection reset by peer
AMQP    [root@irf-centos1 ~]#

当我从Web浏览器中输入相同的URL时,什么都没有发生

请提出建议

注意:此群集是使用kuurem部署在AZure VM上的。为了进行故障排除,我已经打开了这些VM上的所有入站/出站端口,因此,它不应是防火墙,端口阻塞的问题。

编辑1:

我如下修改了服务文件,并重新部署了该文件。 PSB

---
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq
  namespace: default
spec:
  ports:
    - name: ui
      protocol: TCP
      port: 15672
      targetPort: 15672
      nodePort: 31112
    - name: service
      port: 5672
      targetPort: 5672
      protocol: TCP
      nodePort: 31111
  selector:
    app: rabbitmq
  type: NodePort

仍然出现相同的错误

[root@irf-centos1 ~]# curl -I http://guest:guest@10.8.156.187:31111/api/users
curl: (56) Recv failure: Connection reset by peer
AMQP    [root@irf-centos1 ~]# curl -I http://guest:guest@10.8.156.187:31112/api/users
curl: (7) Failed connect to 10.8.156.187:31112; Connection refused

2 个答案:

答案 0 :(得分:1)

对于rabbitmq仪表板/ UI,它运行在:15672

因此,服务文件中的端口号应包括:15672

然后访问仪表板/ UI创建应用程序用户。然后curl使用该用户。

---
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq
  namespace: default
spec:
  ports:
    -
      port: 5672
      targetPort: 5672
      protocol: TCP
      nodePort: 31111
    - 
      protocol: TCP
      port: 15672
      targetPort: 15672
      nodePort: 31112

  selector:
    app: rabbitmqapp
  type: NodePort

或使用rabitmq的默认用户名和密码guest

curl -I http://guest:guest@10.8.156.187:31112/api/users

部署文件添加containerPort:

      image: "docker.io/rabbitmq:latest"
      imagePullPolicy: Always
      name: rabbitmq
      ports:
        -
          containerPort: 5672
          name: http-port
          containerPort: 15672
          name: ui-port

答案 1 :(得分:0)

实际上,使用了错误的docker映像...对于Rabbitmq dashbaord,该docker映像应为docker:management。我改变了它,它起作用了。

这是更新的服务和部署yaml文件:

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: rabbitmq
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: rabbitmq
    spec:
      containers:
        -
          image: "docker.io/rabbitmq:management"
          imagePullPolicy: Always
          name: rabbitmq
          ports:
            -
              containerPort: 15672
              name: http-port
          volumeMounts:
            -
              mountPath: /var/rabbitmqapp_home
              name: rabbitmqapp-home
      volumes:
        -
          emptyDir: {}
          name: rabbitmqapp-home

服务Yaml文件:

---
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq
  namespace: default
spec:
  ports:
    - name: ui
      protocol: TCP
      port: 15672
      targetPort: 15672
      nodePort: 31112
    - name: service
      port: 5672
      targetPort: 5672
      protocol: TCP
      nodePort: 31111
  selector:
    app: rabbitmq
  type: NodePort