Search code examples
kubernetesrabbitmqrabbitmqctl

How to install rabbitmq plugin on kubernetes?


I have a Kubernetes environment with a rabbitmq servirve who deploys 2 pods of rabbitmq.

I need to install a plugin on rabbitmq, (Delayed Message Plugin) but I don't like the "manual" way, so if the pod is deleted, I have to install the plugin again.

I want to know which is the recommended way of achieving this.

FYI: the manual way is to copy a file into the plugins folder, and then launch the following command:

rabbitmq-plugins enable rabbitmq_delayed_message_exchange

Solution

  • You should mount the configuration for RabbitMQ from a config map.

    For example:

    The ConfigMap:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: rabbitmq-config
      namespace: rabbitmq
    data:
      enabled_plugins: |
          [rabbitmq_management,rabbitmq_peer_discovery_k8s].
      rabbitmq.conf: |
          ...
      definitions.json: |
          ...
    

    And then in your Deployment or StatefulSet:

    apiVersion: apps/v1beta1
    kind: StatefulSet
    metadata:
      name: rabbitmq
      namespace: rabbitmq
    spec:
      replicas: 3
      ...
      template:
        ...
        spec:
          containers:
          - image: rabbitmq:3.7.4-management-alpine
            imagePullPolicy: IfNotPresent
            name: rabbitmq
            volumeMounts:
            - name: config-volume
              mountPath: /etc/rabbitmq
            ...
          volumes:
            - name: config-volume
              configMap:
                name: rabbitmq-config
                items:
                - key: rabbitmq.conf
                  path: rabbitmq.conf
                - key: enabled_plugins
                  path: enabled_plugins
                - key: definitions.json
                  path: definitions.json
           ...
    

    There are several ways to install the plugin in the first place. One is to base off of the image you are currently using, add the plugin, and use the new image instead. Alternatively you could utilize Kubernetes life cycle hooks to download the file pre start. Here is an example of postStart