Kubernetes Configmap 目录和子目录文件

时间:2021-04-07 17:11:29

标签: kubernetes

为目录、子目录和文件创建配置映射时出现问题。例如具有如下所示的文件夹结构

.
├── build
│   └── book
│       └── book.txt
├── deploy
│   └── k8
│       └── deploy.txt
└── test
    └── tablet
        └── tab.txt

6 directories, 3 files
apiVersion: v1
kind: ConfigMap
metadata:
  name: testmap
  labels:
    conf: testmap
data:

我真的不知道如何实现以获取配置映射,请您帮助我。

1 个答案:

答案 0 :(得分:1)

这里是步骤

1) select your directory and make it as a tar file (i.e tar -zcvf file.tar.gz /tmp/file)
2) kubectl create configmap test-configmap --from-file=file.tar.gz --dry-run -o yaml >test-configmap.yaml
3) create volume mounts

- mountPath: /tmp/file.tar.gz              
  subPath: file.tar.gz
  name: file

command: ["/bin/sh"]
args: ["-c", "tar -xf /tmp/file.tar.gz while true; do echo hello; sleep 10;done"]

4) create volume as a config map

volumes:
- name: file
configMap: 
            
  name: file
  items:
            
  - key: file.tar.gz
    path: file.tar.gz