我试图创建独立的rabbitmq kubernetes服务。并且数据应该装入我的永久卷。
.....
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
根据我的研究,我了解到Rabbitmq的数据目录为 RABBITMQ_MNESIA_DIR (请参阅https://www.rabbitmq.com/relocate.html)。因此,我只想将此参数设置为“/ data”,以便使用新的PVC(standalone-rabbitmq-pvc-test)保留数据。
您能告诉我如何配置吗?
最佳答案
为了添加路径,创建一个新文件,假设为“rabbitmq.properties”,并添加所需的所有环境变量,每行一个:echo "RABBITMQ_MNESIA_DIR=/data" >> rabbitmq.properties
然后运行kubectl create configmap rabbitmq-config --from-file=rabbitmq.properties
生成configmap。
如果您需要在一个configmap中聚合多个配置文件,请在--from-file
参数中指向文件夹的完整路径
然后您可以运行kubectl get configmaps rabbitmq-config -o yaml
显示创建的Yaml:
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
如果您的configmap的所有其他方面都是正确的,则只需在configmap的data部分中添加以下行:
rabbitmq.properties: |
RABBITMQ_MNESIA_DIR=/data
关于kubernetes - 如何在kubernetes pod中将Rabbitmq数据目录设置为pvc,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59528023/