当前位置: 首页 > wzjs >正文

公司网站怎么做备案网站做导航的地图

公司网站怎么做备案,网站做导航的地图,招聘网站入职分析表怎么做,微信网站开发语言文章目录 前言一、什么是subPath二、subPath使用场景三、场景一示例1.资源准备2.使用subPath字段 四、场景二示例1.资源准备2.测试 前言 在Kubernetes中,挂载存储卷是容器化应用的常见需求。然而当我们将整个卷挂载到容器中的某个目录时,可能会覆盖目标…

文章目录

  • 前言
  • 一、什么是subPath
  • 二、subPath使用场景
  • 三、场景一示例
    • 1.资源准备
    • 2.使用subPath字段
  • 四、场景二示例
    • 1.资源准备
    • 2.测试


前言

在Kubernetes中,挂载存储卷是容器化应用的常见需求。然而当我们将整个卷挂载到容器中的某个目录时,可能会覆盖目标目录中已有的文件,尤其是在共享目录或有多个应用访问同一卷的场景下。为了避免这种情况,subPath字段应运而生,它允许精确指定要挂载的子目录或文件,从而避免覆盖目录中其他重要数据。

在这篇文章中,我们将深入探讨subPath字段的使用方法,展示如何通过这一功能实现精准挂载,确保不干扰或覆盖目录中的其他文件。通过合理利用subPath,你可以在K8s中灵活管理存储,避免数据冲突,提升系统的可维护性和安全性。


一、什么是subPath

subPath是kubernetes中Pod资源volumeMounts字段的挂载选项。
subPath所定义的路径,指的是卷(Volume)内的子路径,用于将卷内subPath所对应的目录或文件,挂载到容器的挂载点,卷内subPath不存在时自动创建。
不指定此参数时,默认是将卷的根路径进行挂载

在这里插入图片描述

二、subPath使用场景

避免覆盖:如果挂载路径是一个已存在的目录,则目录下的内容不会被覆盖。直接将configMap/Secret挂载在容器的路径,会覆盖掉容器路径下原有的文件,使用subpath选定configMap/Secret的指定的key-value挂载在容器中,则不会覆盖掉原目录下的其他文件
文件隔离:pod中含有多个容器共用用一个volume,不同容器日志路径挂载的到不同的子目录,而不是根路径(Subpath目录会在底层存储自动创建且权限为777,无需手动创建)

三、场景一示例

避免目录下的内容被覆盖
在这里插入图片描述

1.资源准备

configMap资源

[root@k8s-master YamlTest]# cat test_cfg.yml
username: "ops"
password: "123"

deployment资源

apiVersion: apps/v1
kind: Deployment
metadata:labels:app: test5-nginxname: test5-nginxnamespace: middleware
spec:replicas: 1selector:matchLabels:app: test5-nginxtemplate:metadata:labels:app: test5-nginxspec:containers:- image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:stablename: nginxvolumeMounts:- name: test5subPath: usernamemountPath: /etc/nginx/usernamevolumes:- name: test5configMap:items:- key: usernamepath: usernamename: test-cfg

默认情况下,该nginx镜像的/etc/nginx目录下存在以下文件
在这里插入图片描述

2.使用subPath字段

[root@k8s-master YamlTest]# kubectl create -f test_nginx.yml

在这里插入图片描述
由此可见,当使用subPath字段后,挂载到nginx目录下的configMap字段以文件的形式存在,并且未影响原目录下的文件及目录。切记以subpath方式挂载文件,文件内容不会随着configMap的更新而自动更新

注意事项(如下所示)
特别注意mountPath和subPath的写法, 最后的path要保持一致.
如mountPath是: /etc/nginx/username; subPath是: username.
mountPath不要漏写为: /etc/nginx

四、场景二示例

pod中含有多个容器共用用一个volume,即不同容器的路径挂载在存储卷volume的子路径

1.资源准备

apiVersion: v1
kind: Pod
metadata:name: pod-subpath-test
spec:containers:- name: subpath-container-1image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:stablevolumeMounts:- mountPath: /tmp/nginx            # 容器1的挂载目录name: subpath-volsubPath: nginxtest1                   # 宿主机volume的子目录1- name: subpath-container-2image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:stable-alpinevolumeMounts:- mountPath: /etc/nginx/nginxtest2             # 容器2的挂载目录name: subpath-volsubPath: nginxtest2                   # 宿主机volume的子目录2 volumes:- name: subpath-volpersistentVolumeClaim:claimName: test-subpath

2.测试

[root@k8s-master default-test-subpath-pvc-6bf62280-0cb5-4df9-a5c1-d5aa0e061725]# pwd
/export/nfs/default-test-subpath-pvc-6bf62280-0cb5-4df9-a5c1-d5aa0e061725
[root@k8s-master default-test-subpath-pvc-6bf62280-0cb5-4df9-a5c1-d5aa0e061725]# ls -l
total 0
drwxrwxrwx 2 root root 15 Mar 10 23:09 nginxtest1
drwxrwxrwx 4 root root 29 Mar 10 23:18 nginxtest2[root@k8s-master default-test-subpath-pvc-6bf62280-0cb5-4df9-a5c1-d5aa0e061725]# cd nginxtest1/
[root@k8s-master nginxtest1]# ll
total 0
-rw-r--r-- 1 root root 0 Mar 10 23:09 1[root@k8s-master nginxtest2]# ll
total 0
drwxr-xr-x 2 root root 6 Mar 10 23:18 ops1[root@k8s-master nginxtest2]# kubectl exec -it pod-subpath-test  bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
Defaulted container "subpath-container-1" out of: subpath-container-1, subpath-container-2
root@pod-subpath-test:/# ls -l /tmp/nginx/
total 0
-rw-r--r-- 1 root root 0 Mar 10 15:09 1        ###在volume目录下创建该文件,容器中也看到了
root@pod-subpath-test:/# ls -l /etc/nginx/
total 24
drwxr-xr-x 1 root root   26 Mar 10 15:14 conf.d
-rw-r--r-- 1 root root 1007 May 28  2024 fastcgi_params
-rw-r--r-- 1 root root 5349 May 28  2024 mime.types
lrwxrwxrwx 1 root root   22 May 29  2024 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root  648 May 29  2024 nginx.conf
drwxr-xr-x 2 root root    6 Mar 10 15:17 ops1               ###在volume目录下创建该目录,容器中也看到了
-rw-r--r-- 1 root root  636 May 28  2024 scgi_params
-rw-r--r-- 1 root root  664 May 28  2024 uwsgi_params


文章转载自:

http://VnDGGJFG.pkmcr.cn
http://6Uv7zdvH.pkmcr.cn
http://2XjlQDXo.pkmcr.cn
http://lpbYteM2.pkmcr.cn
http://nqK4qpt2.pkmcr.cn
http://YFg3PI4Y.pkmcr.cn
http://nhMfhtG6.pkmcr.cn
http://A2oKanxe.pkmcr.cn
http://sSBWsZNp.pkmcr.cn
http://syTiqN4A.pkmcr.cn
http://Fy3hgmNl.pkmcr.cn
http://OGRHF46f.pkmcr.cn
http://ibl2ZBGF.pkmcr.cn
http://5Pg4z4aL.pkmcr.cn
http://UUTNf4EN.pkmcr.cn
http://q8Ea5uCn.pkmcr.cn
http://wqWruHIB.pkmcr.cn
http://4xzBIeRk.pkmcr.cn
http://HIkV2vlj.pkmcr.cn
http://PYGFuDPR.pkmcr.cn
http://8efPczuI.pkmcr.cn
http://aN0f7PoE.pkmcr.cn
http://5IoU49ga.pkmcr.cn
http://BiosMmJs.pkmcr.cn
http://mXJG9Z7a.pkmcr.cn
http://QLEx25kS.pkmcr.cn
http://KN1dA5ul.pkmcr.cn
http://On3qj9xq.pkmcr.cn
http://20zJSssU.pkmcr.cn
http://kyP9e0aL.pkmcr.cn
http://www.dtcms.com/wzjs/650159.html

相关文章:

  • 上线啦 图谱智能网站怎样在网上做推广
  • 北京高端网站公司哪家好女孩学建筑学好找工作吗
  • 手机数据线东莞网站建设技术支持孝义网站建设
  • 平面设计接单的网站北京公司黄页
  • 网站开发无形资产江苏省住房城乡建设厅网站首页
  • 重庆光龙网站建设网站开发有哪些
  • 音乐网站开发参考文献模板王字体网
  • wordpress简约江门网站优化排名
  • 网站关键词优化排名生活做爰网站
  • 网站seo推广员招聘wordpress 修改仪表盘
  • 湖北华路建设工程有限公司网站动漫网站策划书
  • 金泉网做网站多少钱女生学建筑选择什么专业
  • 最新企业网站模板php网站源码建设教程
  • 天津做网站选津坤科技网站网页建设实训心得体会
  • 网站与平台的开发区别百度关键词快速优化
  • 电子商务网站规划报告正规的现货交易平台
  • 嘉兴哪里做网站建设电影网站的目的
  • 宿迁网站推广公司2022推广app赚佣金平台
  • ajax+jsp网站开发从入门到精通手机免费建设网站
  • 旅游网站建设流程北京网站设计制作招聘网
  • 如何创建一个简单的网站公众号登陆
  • 东营网站建设规划书桂林网站艰涩
  • 免费ppt模板 网站开发建设网站一定要数据库吗
  • 网站运营公司做类似淘宝的网站前景
  • 黑龙江专业建站京建站公司
  • 营销推广网站wordpress里面的附件如何导出
  • 企业网站开发步骤阿里巴巴外贸平台中文
  • 购物网站html模板html代码怎么用网页查看
  • vue做网站如何优化seo福州公众号小程序制作公司
  • 长沙哪家制作网站好怎么制作微信网站