參考鏈接:
https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath
我們知道configmap可以通過(guò)掛載文件的方式給pod使用羽利,那如果configmap中包含多組key-value值咧七,而用戶掛載時(shí)按声,只需要其中一組key-value恰矩,并不想全部掛載或者想把key-value掛載到不同的目錄下又沾,那如何做呢?這時(shí)候subPath就有用武之地了瘪匿。
創(chuàng)建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
創(chuàng)建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