Create configmaps from files recursively
Unfortunately, reflecting directory structure in configmap is not supported currently. Workaround is to express directory hierarchy like this:
apiVersion: v1kind: ConfigMapmetadata: name: testconfigdata: file1: | This is file1 file2: | This is file2 in subdir directory---apiVersion: v1kind: Podmetadata: name: testpodspec: 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
An automatable workaround: tar your files, map the tar configmap volume file in /tmp, and untar it at the start of the container.
Create the tar:
tar -cvf conf-d.tar ./conf.dkubectl create configmap conf-d --from-file=conf-d.tarrm conf-d.tar
and in your pod.yml, add the tar -xf before your command, or before your default image command:
command: [ "/bin/sh","-c", "tar -xf /tmp/conf-d.tar -C /etc/ && sleep 1000" ] volumeMounts: - mountPath: /tmp/conf-d.tar name: nginx-config-volume subPath: conf-d.tar