关于k8s中subpath的使用详解
目录
- 有两种情况:
- 1.做为volumes使用时,subPath代表存储卷的子路径:
- 2.作为configmap/secret使用时,subPath代表configmap/secret的子路径:
有两种情况:
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
上一篇:skywalking容器化部署docker镜像构建k8s从测试到可用
栏 目:其它服务器
下一篇:基于docker部署skywalking实现全链路监控功能
本文标题:关于k8s中subpath的使用详解
本文地址:https://zz.feitang.co/server/32072.html
您可能感兴趣的文章
- 12-20Kubernetes中使用临时容器进行故障排查的方法
- 12-20Nginx设置HTTPS的方法步骤
- 12-20二进制方式安装 Kubernetes1.18.3版本实现脚本
- 12-20Nginx工作模式及代理配置的使用细节
- 12-20ZooKeeper分布式协调服务设计核心概念及安装配置
- 12-20Kubernetes部署可视化地图的十个步骤
- 12-20关于docker清理Overlay2占用磁盘空间的问题(亲测有效)
- 12-20Docker compose配置文件写法及命令使用示例
- 12-20openwrt安装docker并启动的操作方法
- 12-20云原生Kubernetes初始化容器Init使用教程


阅读排行
推荐教程
- 12-07一文教你怎么选择Tomcat对应的JDK版本
- 12-07新版Eclipse集成Tomcat时找不到server选项的解决方法
- 12-06IIS7 应用程序池自动回收关闭的解决方案
- 12-05Windows Server 2019安装VMware
- 12-05Windows服务器默认IE浏览器无法下载文件的解决方法
- 12-05Docker安装Jenkins全过程
- 12-19Zabbix SAML SSO 登录绕过漏洞的操作流程
- 12-15Docker-Compose搭建Spark集群的实现方法
- 12-14Docker Desktop无法正常启动解决(failed to start...)
- 12-14k8s 与docker空间使用分析与清理方法





