docker 中的 volume 可以 mount 文件到特定目录,同时保留原有目录不变;同样的 mount 放到 Kubernetes 却变成了:只是把 mount 的几个文件直接放到了根目录,原有目录中文件消失。在很多场景下,我们会希望只是挂载一个文件到容器内部某个目录,而不影响原有目录。
apiVersion: v1
kind: ConfigMap
metadata:
name: special-config
namespace: default
data:
special.level: very
special.type: |-
property.1=value-1
property.2=value-2
property.3=value-3
---
apiVersion: v1
kind: Pod
metadata:
name: test-pod
spec:
containers:
- name: test-container
image: busybox:latest
imagePullPolicy: IfNotPresent
command: [ "/bin/sh", "-c", "ls /etc/", "-c", "ls /usr" ]
volumeMounts:
- name: config-volume
mountPath: /etc/special.level
subPath: special.level
- name: config-volume
mountPath: /usr/special.type
subPath: special.type
volumes:
- name: config-volume
configMap:
# Provide the name of the ConfigMap containing the files you want
# to add to the container
name: special-config
restartPolicy: Never