参考链接:
https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath
我们知道configmap可以通过挂载文件的方式给pod使用,那如果configmap中包含多组key-value值,而用户挂载时,只需要其中一组key-value,并不想全部挂载或者想把key-value挂载到不同的目录下,那如何做呢?这时候subPath就有用武之地了。
创建configmap
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
创建pod使用subPath
apiVersion: v1
kind: Pod
metadata:
name: busybox-pod
spec:
containers:
- name: busybox-container
image: busybox
command: [ "/bin/sh", "-c", "sleep 1000" ]
volumeMounts:
- name: config-volume
mountPath: /etc/special.type
subPath: special.type
- name: config-volume
mountPath: /etc/config/special.level
subPath: special.level
volumes:
- name: config-volume
configMap:
name: special-config
restartPolicy: Never
网友评论