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
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
I've ended mounting a persistent volumen to a shared hard driven, and using the life cycle hooks to copy the file to the correct path
lifecycle:
postStart:
exec:
command: ['sh', '-c', 'cp /data/rabbitmq_delayed_message_exchange-20171201-3.7.x.ez /opt/rabbitmq/plugins/']
Before, I was using the lifecycle to throw a wget to the download url and then unzip and copy the file, but I think the above is more "elegant"
lifecycle:
postStart:
exec:
command: ['sh', '-c', 'wget https://dl.bintray.com/rabbitmq/community-plugins/3.7.x/rabbitmq_delayed_message_exchange/rabbitmq_delayed_message_exchange-20171201-3.7.x.zip && unzip rabbitmq_delayed_message_exchange-20171201-3.7.x.zip -d /opt/rabbitmq/plugins/']