简体   繁体   中英

Rabbitmq in Kubernetes cluster

I'm trying to do something very simple and it doesn't work. I must be doing something stupid but I just can't see it. I hope someone can...

When I run the rabbitmq:latest Docker image on my local docker I can connect to it successfully:

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

Now I'm deploying the image into 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

And I create a service for it:

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: {}

The image successfully deploys:

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 

But after this my other application trying to connect to tcp://rabbitmq:5672 receive a Connection Refused . When I test it myself:

kubectl run --namespace uat -i --tty busybox --image=busybox --restart=Never -- sh
/ # telnet rabbitmq 5672
Connection closed by foreign host

In the rabbitmq logs I can see:

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}

What I'm doing here is so simple I don't see what I missed.

EDIT

I had left that issue on the side because I had no time to work on it. When I tried again a few weeks later it just started working. I didn't change the version of k8s or made any changes to the infrastructure. I'm afraid I don't know what happened

5672 is the AMQP port is not accessible using HTTP .

The management UI uses the port 15672 , but you have enable it:

rabbitmq-plugins enable rabbitmq_management

see this https://www.rabbitmq.com/management.html

then you can use: http://server-name:15672/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM