kubernetes - 递归地从文件创建配置映射
问题描述
我在两个目录中有多个配置文件。例如,
- conf.d/parentconf1.conf
- con.d/node1/child1.conf
- conf.d/node2/child2.conf
我需要使用ConfigMap
.
尝试使用
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 中反映目录结构。解决方法是像这样表达目录层次结构:
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
推荐阅读
- c# - 关于使用外键和值以及主表的建议
- docker - 从主机访问 Redis Docker 容器
- r - 函数未在 R 中返回输出
- android - Android - 内部元素必须是资源引用或为空
- python - 如何在matplotlib中用不均匀的轴隔开x值?
- python - 我无法运行 hello.py 并得到 SyntaxError: invalid syntax
- android - 如何以编程方式更改通知栏中的应用程序名称
- mongodb - 如何从 Retool 更新 Mongodb 中的 One?
- azure - 使用 Powershell 在 Azure 资源中启用诊断日志
- c# - 无法解析主要参考“Google.Apis”