从文件递归创建配置映射 [英] Create configmaps from files recursively
问题描述
我在两个目录中有多个配置文件.例如
I have multiple configuration files in two directories. For example,
- conf.d/parentconf1.conf
- con.d/node1/child1.conf
- conf.d/node2/child2.conf
我需要使用ConfigMap
将这些配置文件以相同的目录结构安装到kubernetes pod.
I need to mount these configuration files in the same directory structure to kubernetes pod using ConfigMap
.
尝试使用
kubectl create configmap --from-file=./conf.d --from-file=./conf.d/node1/child1.conf --from-file=./conf.d/node2/child2.conf.
按预期创建的配置映射无法表达嵌套目录结构.
Config map created, as expected, cannot express the nested directory structure.
是否有可能从文件夹中递归创建ConfigMap,并且仍将文件夹结构保留在ConfigMap的键条目名称中-因为其目的是将这些ConfigMap挂载到Pod中?
Is it possible to create ConfigMap recursively from folders and still retain the folder structure in the name of the key entry for the ConfigMap - since the intention is to mount these ConfigMaps into pods?
推荐答案
不幸的是,当前不支持在configmap中反映目录结构.解决方法是像这样表达目录层次结构:
Unfortunately, reflecting directory structure in configmap is not supported currently. Workaround is to express directory hierarchy like this:
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
这篇关于从文件递归创建配置映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!