日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

關于k8s中subpath的使用詳解_云其它

作者:fengjian1585 ? 更新時間: 2022-04-28 編程語言

有兩種情況:

1.做為volumes使用時,subPath代表存儲卷的子路徑:

apiVersion: v1
kind: Pod
metadata:
  name: testpod0
spec:
  containers:
  - name: testc
    image: busybox
    command: ["/bin/sleep","10000"]
    volumeMounts:
      - name: data
        mountPath: /opt/data    # 掛載的路徑
        subPath: data           # volume的子路徑
        mountPath: /opt/model
        subPath: model
  volumes:
    - name: data
      persistentVolumeClaim:
        claimName: test-data

2.作為configmap/secret使用時,subPath代表configmap/secret的子路徑:

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-test
data:
  config.ini: "hello"
  config.conf: "nihao"

單獨掛載一個key為文件

apiVersion: v1
kind: Pod
metadata:
  name: testpod
spec:
  containers:
  - name: testc
    image: busybox
    command: ["/bin/sleep","10000"]
    volumeMounts:
      - name: config-test
        mountPath: /etc/config.ini   # 最終在容器中的文件名
        subPath: config.ini  #要掛載的confmap中的key的名稱
  volumes:
    - name: config-test
      configMap:
        name: config-test

掛載多個key為文件:

apiVersion: v1
kind: Pod
metadata:
  name: testpod2
spec:
  containers:
  - name: testc
    image: busybox
    command: ["/bin/sleep","10000"]
    volumeMounts:
      - name: config-test
        mountPath: /etc/config.ini   # 最終在容器中的文件名
        subPath: config.ini  #要掛載的confmap中的key的名稱
        mountPath: /etc/config.conf   # 最終在容器中的文件名
        subPath: config.conf  #要掛載的confmap中的key的名稱
  volumes:
    - name: config-test
      configMap:
        name: config-test

多個container掛載不同的key:

apiVersion: v1
kind: Pod
metadata:
  name: testpod1
spec:
  containers:
  - name: testc
    imagePullPolicy: Never
    image: busybox
    command: ["/bin/sleep","10000"]
    volumeMounts:
      - name: config-test
        mountPath: /etc/config/config.ini
        subPath: config.ini
  - name: testc1
    imagePullPolicy: Never
    image: busybox
    command: ["/bin/sleep","10000"]
    volumeMounts:
      - name: config-test
        mountPath: /etc/config/config.conf
        subPath: config.conf
  volumes:
    - name: config-test
      configMap:
        name: config-test
        items:
        - key: config.ini
          path: config.ini
        - key: config.conf
          path: config.conf

摘自

https://soulchild.cn/1911.html

原文鏈接:https://www.cnblogs.com/fengjian2016/p/15935985.html

欄目分類
最近更新