在我们的应用程序中,我们将有一个Kubernetes作业,它将基于一组(旧版)配置文件来引导微服务。这些文件在旧版应用程序中打包为文件结构,我们希望保留此结构,这样我们就无需为Kubernetes变体和旧版变体维护不同的配置文件打包,并且有很多我们仍然希望使用的旧代码需要此文件结构。
我的方法是我想在作业窗格中安装ConfigMap
,因为我天真地假定您可以映射整个文件夹树,但是ConfigMap
是平面键值存储。
我们正在使用Helm,所以我们的想法是,微服务将包括该作业,并使用钩子对其进行应用。将配置文件结构映射到作业窗格的一种好方法是什么?您能否轻松创建一个卷,并用strucutre文件填充它,然后将其安装在作业窗格中?
您可以从create a configmap或file和directory中选择add configmap data to a volume。这将从已安装目录中的configmap键创建只读文件。
configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: special-config
data:
some.properties: |
foo=bar
other.properties: |
baz=qux
pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
args:
- /bin/sh
- -c
- ls -la /etc/config; cat /etc/config/some/some.properties; cat /etc/config/other.properties
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
name: special-config
items:
- key: some.properties
path: some/some.properties
- key: other.properties
path: other.properties
使用kubectl logs test
检查日志
drwxrwxrwx 3 root root 95 May 29 09:14 .
drwxr-xr-x 1 root root 20 May 29 09:14 ..
drwxr-xr-x 3 root root 42 May 29 09:14 ..2020_05_29_09_14_34.418889646
lrwxrwxrwx 1 root root 31 May 29 09:14 ..data -> ..2020_05_29_09_14_34.418889646
lrwxrwxrwx 1 root root 23 May 29 09:14 other.properties -> ..data/other.properties
lrwxrwxrwx 1 root root 11 May 29 09:14 some -> ..data/some
foo=bar
baz=qux