gpt4 book ai didi

kubernetes - 递归地从文件创建配置映射

转载 作者:行者123 更新时间:2023-12-02 11:29:17 24 4
gpt4 key购买 nike

我在两个目录中有多个配置文件。例如,

  • conf.d/parentconf1.conf
  • con.d/node1/child1.conf
  • conf.d/node2/child2.conf

  • 我需要使用 ConfigMap 将相同目录结构中的这些配置文件挂载到 kubernetes pod .

    尝试使用
    kubectl create configmap --from-file=./conf.d --from-file=./conf.d/node1/child1.conf --from-file=./conf.d/node2/child2.conf. 

    按预期创建的配置映射无法表达嵌套的目录结构。

    是否可以从文件夹递归创建 ConfigMap 并仍然以 ConfigMap 的关键条目的名称保留文件夹结构 - 因为目的是将这些 ConfigMap 安装到 pod 中?

    最佳答案

    不幸的是,目前不支持在 configmap 中反射(reflect)目录结构。解决方法是像这样表达目录层次结构:

    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: testconfig
    data:
    file1: |
    This is file1
    file2: |
    This is file2 in subdir directory
    ---
    apiVersion: v1
    kind: Pod
    metadata:
    name: testpod
    spec:
    restartPolicy: Never
    containers:
    - name: test-container
    image: gcr.io/google_containers/busybox
    command: [ "/bin/sh","-c", "sleep 1000" ]
    volumeMounts:
    - name: config-volume
    mountPath: /etc/config
    volumes:
    - name: config-volume
    configMap:
    name: testconfig
    items:
    - key: file2
    path: subdir/file2
    - key: file1
    path: file1

    关于kubernetes - 递归地从文件创建配置映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55790144/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com