有两种情况:
1.做为volumes使用时,subPath代表存储卷的子路径:apiVersion: v1kind: Podmetadata: name: testpod0spec: 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: v1kind: ConfigMapmetadata: name: config-testdata: config.ini: "hello" config.conf: "nihao" 单独挂载一个key为文件 apiVersion: v1kind: Podmetadata: name: testpodspec: 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: v1kind: Podmetadata: name: testpod2spec: 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: v1kind: Podmetadata: name: testpod1spec: 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 下载地址: 在vmware虚拟机安装dpdk的详细过程 Ansible部署K8s集群的方法 |