K8S中使用SubPath

參考鏈接:
https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath

我們知道configmap可以通過掛載文件的方式給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

觀察文件掛載情況

image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容