小知识:关于k8s中subpath的使用详解

有两种情况:

1.做为volumes使用时,subPath代表存储卷的子路径:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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的子路径:

?
1
2
3
4
5
6
7
apiVersion: v1
kind: ConfigMap
metadata:
name: config-test
data:
config.ini: “hello”
config.conf: “nihao”

单独挂载一个key为文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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为文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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

到此这篇关于关于k8s中subpath的使用详解的文章就介绍到这了,更多相关k8s subpath使用内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

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

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:Ansible部署K8s集群的方法

2023-3-9 16:49:04

建站知识

小知识:在vmware虚拟机安装dpdk的详细过程

2023-3-9 17:03:27

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索