Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly setup RabbitMQ on Openshift

I have created new app on OpenShift using this image: https://hub.docker.com/r/luiscoms/openshift-rabbitmq/

It runs successfully and I can use it. I have added a persistent volume to it. However, every time a POD is restarted, I loos all my data. This is because RabbitMq uses a hostname to create database directory.

For example:

node           : rabbit@openshift-rabbitmq-11-9b6p7
home dir       : /var/lib/rabbitmq
config file(s) : /etc/rabbitmq/rabbitmq.config
cookie hash    : BsUC9W6z5M26164xPxUTkA==
log            : tty
sasl log       : tty
database dir   : /var/lib/rabbitmq/mnesia/rabbit@openshift-rabbitmq-11-9b6p7

How can I set RabbitMq to always use same database dir?

like image 957
dplesa Avatar asked Mar 09 '23 09:03

dplesa


1 Answers

You should be able to set an environment variable RABBITMQ_MNESIA_DIR to override the default configuration. This can be done via the OpenShift console by add an entry to environment in the deployment config or via the oc tool, for example:

oc set env dc/my-rabbit RABBITMQ_MNESIA_DIR=/myDir

You would then need to mount the persistent volume inside the Pod at the required path. Since you have said it is already created, then you just need to update it, example:

oc volume dc/my-rabbit --add --overwrite --name=my-pv-name --mount-path=/myDir

You will need to make sure you have correct r/w access on the provided mount path

EDIT: Some additional workarounds based on issues in comments

The issues caused by the dynamic hostname could be solved in a number of ways:

1.(Preferred IMO) Move the deployment to a StatefulSet. StatefulSet will provide stability in the naming and hence network identifier of the Pod, which must be fronted by a headless service. This feature is out of beta as of Kubernetes 1.9 and tech preview in OpenShift since version 3.5

  1. Set the hostname for the Pod if Statefulsets are not an option. This can be done by adding the environment variable oc set env dc/example HOSTNAME=example to make the hostname static and setting RABBITMQ_NODENAME to do likewise.
like image 124
PhilipGough Avatar answered Mar 14 '23 19:03

PhilipGough