我正在尝试做一些非常简单的事情,但它不起作用。我一定在做一些愚蠢的事情,但是我看不到它。我希望有人可以...

当我在本地docker上运行rabbitmq:latest Docker镜像时,我可以成功连接到它:

docker run -p 5672:5672 -d rabbitmq
telnet <dockerMachineIp> 5672
Trying x.y.z.w...
Connected to x.y.z.w.

现在,我将镜像部署到k8s中:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    run: rabbitmq
  name: rabbitmq
  namespace: uat
spec:
  replicas: 1
  selector:
    matchLabels:
      env: uat
      run: rabbitmq
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        env: uat
        run: rabbitmq
    spec:
      containers:
      - image: rabbitmq
        imagePullPolicy: Always
        name: rabbitmq
        ports:
        - containerPort: 5672
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          tcpSocket:
            port: 5672
          initialDelaySeconds: 15
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        livenessProbe:
          failureThreshold: 3
          tcpSocket:
            port: 5672
          initialDelaySeconds: 15
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          limits:
            cpu: 100m
            memory: 150Mi
          requests:
            cpu: 100m
            memory: 150Mi
        terminationMessagePath: /dev/termination-log
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  availableReplicas: 1
  observedGeneration: 2
  replicas: 1
  updatedReplicas: 1

我为此创建了一个服务:
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq
  namespace: uat
spec:
  ports:
  - name: tcp5672
    port: 5672
    protocol: TCP
    targetPort: 5672
  selector:
    run: rabbitmq
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

镜像成功部署:
2016-08-16T06:08:15.903787400Z =INFO REPORT==== 16-Aug-2016::06:08:15 ===
2016-08-16T06:08:15.903793115Z started TCP Listener on [::]:5672
2016-08-16T06:08:15.911128257Z  completed with 0 plugins.
2016-08-16T06:08:15.911479872Z
2016-08-16T06:08:15.911492347Z =INFO REPORT==== 16-Aug-2016::06:08:15 ===
2016-08-16T06:08:15.911497759Z Server startup complete; 0 plugins started.
2016-08-16T06:11:00.901609310Z

但是之后,尝试连接到tcp://rabbitmq:5672的其他应用程序收到了Connection Refused。当我自己测试时:
kubectl run --namespace uat -i --tty busybox --image=busybox --restart=Never -- sh
/ # telnet rabbitmq 5672
Connection closed by foreign host

在rabbitmq日志中,我可以看到:
2016-08-16T07:38:48.465296167Z =INFO REPORT==== 16-Aug-2016::07:38:48 ===
2016-08-16T07:38:48.465302171Z accepting AMQP connection <0.3666.0> (10.244.66.6:50968 -> 10.244.64.4:5672)
2016-08-16T07:38:48.465391749Z
2016-08-16T07:38:48.465408673Z =ERROR REPORT==== 16-Aug-2016::07:38:48 ===
2016-08-16T07:38:48.465414738Z closing AMQP connection <0.3666.0> (10.244.66.6:50968 -> 10.244.64.4:5672):
2016-08-16T07:38:48.465420105Z {handshake_timeout,handshake}

我在这里做的事情是如此简单,我看不到我错过的一切。

编辑

我把这个问题放在一边,因为我没有时间去处理它。几周后再次尝试时,它才开始工作。我没有更改k8s的版本,也没有更改基础架构。恐怕我不知道发生了什么

最佳答案

5672是使用HTTP无法访问AMQP端口。

管理UI使用端口15672,但是您已启用它:

rabbitmq-plugins enable rabbitmq_management

看到这个https://www.rabbitmq.com/management.html

那么您可以使用:http://server-name:15672/

关于docker - Kubernetes集群中的Rabbitmq,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38969195/

10-11 03:35
查看更多