I tried to create standalone rabbitmq kubernetes service. And the data should be mount to my persistent volume.
.....
apiVersion: v1
kind: ConfigMap
metadata:
name: rabbitmq-config
data:
enabled_plugins: |
[rabbitmq_management,rabbitmq_peer_discovery_k8s].
rabbitmq.conf: |
loopback_users.guest = false
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: standalone-rabbitmq
spec:
serviceName: standalone-rabbitmq
replicas: 1
template:
.....
volumeMounts:
- name: config-volume
mountPath: /etc/rabbitmq
- name: standalone-rabbitmq-data
mountPath: /data
- name: config-volume
configMap:
name: rabbitmq-config
items:
- key: rabbitmq.conf
path: rabbitmq.conf
- key: enabled_plugins
path: enabled_plugins
- name: standalone-rabbitmq-data
persistentVolumeClaim:
claimName: standalone-rabbitmq-pvc-test
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: standalone-rabbitmq-pvc-test
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: test-storage-class
According to my research, I understood that data directory of rabbitmq is RABBITMQ_MNESIA_DIR (please see https://www.rabbitmq.com/relocate.html). So I just wanted to set this parameter “/data”, so that my new PVC(standalone-rabbitmq-pvc-test) is used to keep the data. Can you tell me how to configurate this?
In order to add the path, create a new file, let's say 'rabbitmq.properties' and add all the environment variables you'll need, one per line: echo "RABBITMQ_MNESIA_DIR=/data" >> rabbitmq.properties
Then run kubectl create configmap rabbitmq-config --from-file=rabbitmq.properties
to generate the configmap.
If you need to aggregate multiple config files in one configmap point the folder's full path in the --from-file
argument
Then you can run kubectl get configmaps rabbitmq-config -o yaml
to display the yaml that was created:
user@k8s:~$ kubectl get configmaps rabbitmq-config -o yaml
apiVersion: v1
data:
rabbitmq.properties: |
RABBITMQ_MNESIA_DIR=/data
kind: ConfigMap
metadata:
creationTimestamp: "2019-12-30T11:33:27Z"
name: rabbitmq-config
namespace: default
resourceVersion: "1106939"
selfLink: /api/v1/namespaces/default/configmaps/rabbitmq-config
uid: 4c6b1599-a54b-4e0e-9b7d-2799ea5d9e39
If all other aspects of your configmap is correct, you can just add in the data section of your configmap this lines:
rabbitmq.properties: |
RABBITMQ_MNESIA_DIR=/data
HTH, So pretty much here's my configuration. From which you can see there are mount points. First is the data, second is config and third is definitions respectively as in the YML mentioned below.
volumeMounts:
- mountPath: /var/lib/rabbitmq
name: rmqdata
- mountPath: /etc/rabbitmq
name: config
- mountPath: /etc/definitions
name: definitions
readOnly: true
And here's the PVC template stuff.
volumeClaimTemplates:
- metadata:
creationTimestamp: null
name: rmqdata
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi
storageClassName: nfs-provisioner
volumeMode: Filesystem
Post Update: As per the comments, you can mount it directly to the data
folder like this. The section where you assign the rmqdata
to mountpath will stay the same.
volumes:
- hostPath:
path: /data
type: DirectoryOrCreate
name: rmqdata