<p>I have a Kubernetes environment with a rabbitmq servirve who deploys 2 pods of rabbitmq.</p>

<p>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.</p>

<p>I want to know which is the recommended way of achieving this. </p>

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

<pre><code>rabbitmq-plugins enable rabbitmq_delayed_message_exchange
</code></pre>

<p>You should mount the configuration for RabbitMQ from a config map.</p>

<p>For example:</p>

<p>The ConfigMap:</p>

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

<p>And then in your Deployment or StatefulSet:</p>

<pre><code>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
       ...
</code></pre>

<p>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 <a href="https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/" rel="noreferrer">Kubernetes life cycle hooks</a> to download the file pre start. Here is an <a href="https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/" rel="noreferrer">example of postStart</a></p>
