我试图创建独立的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)保留数据。 你能告诉我如何配置吗?
答案 0 :(得分:0)
HTH,差不多是我的配置。从中可以看到挂载点。首先是数据,第二是config,第三是定义,如下所述。
volumeMounts:
- mountPath: /var/lib/rabbitmq
name: rmqdata
- mountPath: /etc/rabbitmq
name: config
- mountPath: /etc/definitions
name: definitions
readOnly: true
这是PVC模板的内容。
volumeClaimTemplates:
- metadata:
creationTimestamp: null
name: rmqdata
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi
storageClassName: nfs-provisioner
volumeMode: Filesystem
更新后:根据注释,您可以像这样将其直接安装到data
文件夹中。将rmqdata
分配给mountpath的部分将保持不变。
volumes:
- hostPath:
path: /data
type: DirectoryOrCreate
name: rmqdata
答案 1 :(得分:0)
为了添加路径,创建一个新文件,假设'rabbitmq.properties'并添加所需的所有环境变量,每行一个:
echo "RABBITMQ_MNESIA_DIR=/data" >> rabbitmq.properties
然后运行kubectl create configmap rabbitmq-config --from-file=rabbitmq.properties
生成配置图。
如果您需要在一个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