Kubernetes deploys rabbitmq cluster

  kubernetes, rabbitmq

dockerfile

FROM rabbitmq:3.6.8

ENV RABBITMQ_USE_LONGNAME=true \
    AUTOCLUSTER_LOG_LEVEL=debug \
    AUTOCLUSTER_CLEANUP=true \
    CLEANUP_INTERVAL=60 \
    CLEANUP_WARN_ONLY=false \
    AUTOCLUSTER_TYPE=k8s \
    LANG=en_US.UTF-8

ADD plugins/*.ez /usr/lib/rabbitmq/lib/rabbitmq_server-3.6.8/plugins/

RUN rabbitmq-plugins enable --offline autocluster
RUN rabbitmq-plugins enable --offline rabbitmq_management

deployment

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: rabbitmq
  namespace: cat  
  labels:
    app: rabbitmq  
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: rabbitmq
    spec:
      containers:
      - name: rabbitmq
        image: registry.cn-hangzhou.aliyuncs.com/codecraft/kubernetes-rabbitmq-autocluster:mgr
        ports:
          - containerPort: 5672
            name: port-5672
          - containerPort: 4369
            name: port-4369
          - containerPort: 5671
            name: port-5671
          - containerPort: 15672
            name: port-15672
          - containerPort: 25672
            name: port-25672
        env:
          - name: HOSTNAME
            valueFrom:
             fieldRef:
              fieldPath: status.podIP
          - name: MY_POD_IP
            valueFrom:
             fieldRef:
              fieldPath: status.podIP
          - name: AUTOCLUSTER_CLEANUP
            value: "true"
          - name: CLEANUP_INTERVAL
            value: "60"
          - name: CLEANUP_WARN_ONLY
            value: "false"
          # start.sh will store this value to a proper location in filesystem
          - name: RABBITMQ_ERLANG_COOKIE
            valueFrom:
             secretKeyRef:
              name: erlang.cookie
              key: erlang.cookie

svc

apiVersion: v1
kind: Service
metadata:
  labels:
    app: rabbitmq
  name: rabbitmq
  namespace: cat  
spec:
  ports:
  - port: 5672
    name: port-5672
    protocol: TCP
    targetPort: 5672    
  - port: 4369
    name: port-4369
    protocol: TCP
    targetPort: 4369    
  - port: 5671
    name: port-5671
    protocol: TCP
    targetPort: 5671    
  - port: 15672
    name: port-15672
    protocol: TCP
    targetPort: 15672    
  - port: 25672
    name: port-25672
    protocol: TCP
    targetPort: 25672    
  selector:
    app: rabbitmq
  clusterIP: 10.0.0.165   
  externalIPs:
    - 192.168.99.101    

Create erlang cookie

echo $(openssl rand -base64 32) > erlang.cookie
kubectl -n cat create secret generic erlang.cookie --from-file=erlang.cookie

run

kubectl -n cat create -f manifestos/rabbitmq-deploy.yaml
kubectl -n cat create -f manifestos/rabbitmq-svc.yaml

Access

http://192.168.99.101:15672/#/
guest/guest图片描述

doc


For the latest content, please pay attention to WeChat public number
图片描述