22.3.3. 在卷中消耗
ConfigMap
也可以被消耗在卷中。再次返回到以下示例 ConfigMap
:
apiVersion: v1 kind: ConfigMap metadata: name: special-config namespace: default data: special.how: very special.type: charm
在卷中消耗此 ConfigMap
时有两个不同的选项。最基本的方法是使用文件来填充卷,其中键为文件名,键值是文件的内容:
apiVersion: v1 kind: Pod metadata: name: dapi-test-pod spec: containers: - name: test-container image: gcr.io/google_containers/busybox command: [ "/bin/sh", "cat", "/etc/config/special.how" ] volumeMounts: - name: config-volume mountPath: /etc/config volumes: - name: config-volume configMap: name: special-config restartPolicy: Never
当此 pod 运行时,输出将是:
very
您还可以控制投射 ConfigMap
键的卷中的路径:
apiVersion: v1 kind: Pod metadata: name: dapi-test-pod spec: containers: - name: test-container image: gcr.io/google_containers/busybox command: [ "/bin/sh", "cat", "/etc/config/path/to/special-key" ] volumeMounts: - name: config-volume mountPath: /etc/config volumes: - name: config-volume configMap: name: special-config items: - key: special.how path: path/to/special-key restartPolicy: Never
当此 pod 运行时,输出将是:
very