如何挂载couchDB的配置文件?

wfypjpf4  于 2023-10-14  发布在  CouchDB
关注(0)|答案(1)|浏览(239)

我想将couchdb-config挂载到我的CouchDB部署中。
这是我的沙发yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: couchdb-delp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: couchdb
  template:
    metadata:
      labels:
        app: couchdb
    spec:
      containers:
      - name: couchdb
        image: couchdb:latest
        env:
        - name: COUCHDB_USER
          value: admin
        - name: COUCHDB_PASSWORD
          value: password
        ports:
          - name: couchdb
            containerPort: 5984
        volumeMounts:
        - name: couchdb-config
          mountPath: /opt/couchdb/etc/local.ini
      volumes:
      - name: couchdb-config
        configMap:
          name: couchdb-config

这是我的couchdb-config

apiVersion: v1
kind: ConfigMap
metadata:
  name: couchdb-config
data:
  local.ini: |
    [chttpd]
    enable_cors = true

    [httpd]
    port = 5984

    [couch_peruser]
    enable = true

    [cors]
    origin: "*"
    credentials: true
    methods: GET,PUT,POST,HEAD,DELETE
    headers: accept, authorization, content-type, origin, referer

然后我得到这个错误msg -> Error msg image

Error: failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/var/lib/kubelet/pods/c2895190-e2cc-4ccf-acb0-a41b65edf510/volumes/kubernetes.io~configmap/couchdb-config" to rootfs at "/opt/couchdb/etc/local.ini": mount /var/lib/kubelet/pods/c2895190-e2cc-4ccf-acb0-a41b65edf510/volumes/kubernetes.io~configmap/couchdb-config:/opt/couchdb/etc/local.ini (via /proc/self/fd/6), flags: 0x5001: not a directory: unknown

我之前也包含了subPath。但我也得到了错误
这是在yaml中挂载couchdb配置的方法吗?

vxf3dgd4

vxf3dgd41#

将配置Map挂载为文件夹,然后将其作为文件引用。
根据文档,它不是这样工作的。
你需要做的是以下几点(未经测试,但你得到的图片):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: couchdb-delp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: couchdb
  template:
    metadata:
      labels:
        app: couchdb
    spec:
      containers:
      - name: couchdb
        image: couchdb:latest
        env:
        - name: COUCHDB_USER
          value: admin
        - name: COUCHDB_PASSWORD
          value: password
        ports:
          - name: couchdb
            containerPort: 5984
        volumeMounts:
        - name: couchdb-config
          mountPath: /opt/couchdb/etc/  # Note the missing filename
      volumes:
      - name: couchdb-config
        configMap:
          name: couchdb-config
          items:
            - key: local.ini   # The name of the key in the ConfigMap
              path: local.ini  # The name of the file when in the filesystem

然而,这会导致一个不同的问题:由于您在/opt/couchdb/etc上挂载了一个只读“文件系统”,而couchdb在/opt/couchdb/local.d中运行,因此您需要将另一个卷挂载到这个挂载点/opt/couchdb/local.d
根据image's documentation的建议解决方案是创建一个自定义的Docker镜像,这很容易:

FROM couchdb

COPY local.ini /opt/couchdb/etc/

另一个解决方案是official Helm chart of couchDB所做的:"init container"用于将从配置Map和机密中挂载的数据包带到临时路径,并将它们复制到为/opt/local/etc提供的卷。
如果你只想部署CouchDB,我强烈建议使用Helm Chart。

相关问题