如何在kubernetes容器中将Rabbitmq数据目录设置为pvc

问题描述 投票:0回答:2

我试图创建独立的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)保留数据。您能告诉我如何配置吗?

kubernetes rabbitmq
2个回答
0
投票

HTH,几乎是我的配置。从中可以看到挂载点。首先是数据,第二是config,第三是定义,如下面提到的YML所示。

     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

0
投票

为了添加路径,创建一个新文件,假设'rabbitmq.properties'并添加您需要的所有环境变量,每行添加一个:echo "RABBITMQ_MNESIA_DIR=/data" > rabbitmq.properties

然后运行kubectl create configmap rabbitmq-config --from-file=rabbitmq.properties以生成配置图。

如果需要在一个配置映射中聚合多个配置文件,请在--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
© www.soinside.com 2019 - 2024. All rights reserved.