k8s消息队列-rabbiMQ集群(pod初始化安装消息延迟插件)

一、方案:在k8s上部署rabbitMQ集群,pod初始化时安装消息延迟插件。

二、部署

参考rabbitMQ官方:https://www.rabbitmq.com/kubernetes/operator/operator-overview.html

1、部署cluster operator

kubectl apply -f "https://github.com/rabbitmq/cluster-operator/releases/latest/download/cluster-operator.yml"

2、部署RabbitmqCluster

说明:

由于资源限制RabbitmqCluster副本数量改成了1,可视实际情况修改。

集群存储采用了nfs,nfs部署方法请参考nfs文章。

rabbitmq-install-plugins.yml

apiVersion: rabbitmq.com/v1beta1
kind: RabbitmqCluster
metadata:
  name: rabbitmq
spec:
  replicas: 1
  override:
    statefulSet:
      spec:
        template:
          spec:
            containers:
              - name: rabbitmq
                volumeMounts:
                  - mountPath: /opt/rabbitmq/community-plugins
                    name: community-plugins
            volumes:
              - name: community-plugins
                emptyDir: {}
            initContainers:
              - command:
                  - sh
                  - -c
                  - curl -L -v https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/3.8.17/rabbitmq_delayed_message_exchange-3.8.17.8f537ac.ez --output /community-plugins/rabbitmq_delayed_message_exchange-3.8.17.8f537ac.ez
                image: curlimages/curl
                imagePullPolicy: IfNotPresent
                name: copy-community-plugins
                resources:
                  limits:
                    cpu: 100m
                    memory: 500Mi
                  requests:
                    cpu: 100m
                    memory: 500Mi
                terminationMessagePolicy: FallbackToLogsOnError
                volumeMounts:
                  - mountPath: /community-plugins/
                    name: community-plugins
  rabbitmq:
    additionalConfig: |
      default_user=guest
      default_pass=guest
    additionalPlugins:
      - rabbitmq_delayed_message_exchange
    envConfig: |
      PLUGINS_DIR=/opt/rabbitmq/plugins:/opt/rabbitmq/community-plugins
  image: rabbitmq:3.8-management
  service:
    type: NodePort
  persistence:
    storageClassName: nfs-client
    storage: 1Gi
kubectl apply -f rabbitmq-install-plugins.yml

3、部署rabbitmq  ingress

rabbitmq-ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: rabbitmq-ingress
  namespace: default 
spec:
  ingressClassName: nginx
  rules:
  - host: "test.rabbitmq.com"
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: rabbitmq
            port:
              number: 15672
kubectl apply -f rabbitmq-ingress.yaml

4、本机添加hosts配置

192.168.152.10 test.rabbitmq.com

三、验证

浏览器访问test.rabbitmq.com

 

posted @ 2022-09-29 17:39  屠夫2022  阅读(1070)  评论(0编辑  收藏  举报