广告
返回顶部
首页 > 资讯 > 服务器 >关于k8s中subpath的使用详解
  • 755
分享到

关于k8s中subpath的使用详解

2024-04-02 19:04:59 755人浏览 独家记忆
摘要

目录有两种情况: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

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

--结束END--

本文标题: 关于k8s中subpath的使用详解

本文链接: https://www.lsjlt.com/news/140544.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作