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

做问卷调查的网站挣钱搜索引擎推广培训

做问卷调查的网站挣钱,搜索引擎推广培训,新乡网站设计,长沙制作网页联系方式1 mountPath mountPath是容器内部文件系统的挂载点,它定义了容器内部将外部存储卷(如 PersistentVolume、ConfigMap、Secret 等)挂载到哪个路径下。通过 mountPath,容器可以访问这些挂载的数据或配置。 2 subPath subPath 是 m…

1 mountPath

mountPath是容器内部文件系统的挂载点,它定义了容器内部将外部存储卷(如 PersistentVolume、ConfigMap、Secret 等)挂载到哪个路径下。通过 mountPath,容器可以访问这些挂载的数据或配置。

2 subPath

subPath 是 mountPath 下的子路径,它允许容器将挂载的数据卷中的特定文件或目录挂载到容器中的指定路径下。这样可以实现更加精细的文件系统级别的访问控制。

3 mountPath使用场景

比如我需要创建一个nginx deployment,需要将自定义的nginx.conf配置文件独立出来,作为一个configmap来挂载到pod中。

apiVersion: v1
kind: ConfigMap
metadata:name: nginx-config
data:my-nginx.conf: |server {listen       80;server_name  localhost;location / {root   /usr/share/nginx/html;index  index.html index.htm;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   /usr/share/nginx/html;}}
---
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-deployment
spec:replicas: 1selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: nginxvolumeMounts:- name: nginx-config-volumemountPath: /etc/nginx/conf.dvolumes:- name: nginx-config-volumeconfigMap:name: nginx-config

部署完成后,你可以进入pod,可以看到如下文件,这就是通过configmap挂载到容器中。

kubectl exec -it nginx-deployment-5b4699b7dd-fh4qc -- /bin/sh
# cd /etc/nginx/conf.d
# ls
my-nginx.conf

4 subPath使用场景

如果我想直接通过configmap定义/etc/nginx/nginx.conf,这时候如果还是只使用mountPath,就会有问题了。

apiVersion: v1
kind: ConfigMap
metadata:name: nginx-config
data:nginx.conf: |user  nginx;worker_processes  auto;error_log  /var/log/nginx/error.log notice;pid        /var/run/nginx.pid;events {worker_connections  1024;}http {include       /etc/nginx/mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  /var/log/nginx/access.log  main;sendfile        on;#tcp_nopush     on;keepalive_timeout  65;#gzip  on;include /etc/nginx/conf.d/*.conf;}---
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-deployment
spec:replicas: 1selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: nginxvolumeMounts:- name: nginx-config-volumemountPath: /etc/nginxvolumes:- name: nginx-config-volumeconfigMap:name: nginx-config

创建容器后,服务无法起来,会报错,因为此时容器中的/etc/nginx/目录会被我们挂载的configmap给覆盖,所以原先/etc/nginx/目录下的文件都无法被pod访问,也就报错了。

2024/03/25 06:56:58 [emerg] 1#1: open() "/etc/nginx/mime.types" failed (2: No such file or directory) in /etc/nginx/nginx.conf:14
nginx: [emerg] open() "/etc/nginx/mime.types" failed (2: No such file or directory) in /etc/nginx/nginx.conf:14

那如果我将volumeMount改为如下配置呢,

      - name: nginximage: nginxvolumeMounts:- name: nginx-config-volumemountPath: /etc/nginx/nginx.conf

此时原来/etc/nginx/目录下的文件都不会受影响,但是依旧会报错,连容器都无法创建,

Error: failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/var/lib/kubelet/pods/6755a0be-2f05-4edb-813b-ece2dcc2e8f1/volumes/kubernetes.io~configmap/nginx-config-volume" to rootfs at "/etc/nginx/nginx.conf": mount /var/lib/kubelet/pods/6755a0be-2f05-4edb-813b-ece2dcc2e8f1/volumes/kubernetes.io~configmap/nginx-config-volume:/etc/nginx/nginx.conf (via /proc/self/fd/6), flags: 0x5001: not a directory: unknown

这是因为此时容器中/etc/nginx/nginx.conf这个路径已经是存在的,镜像中默认的文件,没法作为mountpath使用。

当然,你可以将nginx.conf换成其他名字,比如mynginx.conf,

      - name: nginximage: nginxvolumeMounts:- name: nginx-config-volumemountPath: /etc/nginx/mynginx.conf

这样就不会报错,但是这样的效果是,容器中会创建一个目录/etc/nginx/mynginx.conf/,这个目录下有个文件nginx.conf,与最开始我们在/etc/nginx/conf.d/定义my-nginx.conf一样,但这并不是我们所要的。

kubectl exec -it nginx-deployment-6bf5f55df8-f452d -- /bin/sh
# cd /etc/nginx/mynginx.conf/
# ls
nginx.conf

这个时候,我们就需要使用subPath了,将volumeMount做如下修改,

      - name: nginximage: nginxvolumeMounts:- name: nginx-config-volumemountPath: /etc/nginx/nginx.confsubPath: nginx.conf

这时服务就按照我们预期启动了,容器内文件如下,而且nginx.conf的内容就是我们configmap中定义的配置,

kubectl exec -it nginx-deployment-bb7d454c6-75bwz -- /bin/sh
# cd /etc/nginx/
# ls
conf.d	fastcgi_params	mime.types  modules  nginx.conf  scgi_params  uwsgi_params

类似的场景,比如需要在/etc/nginx/conf.d/为不同的host定义不同的配置,我们就可以创建多个configmap,配合使用subPath来挂载到同一个目录下,

      - name: nginximage: nginxvolumeMounts:- name: nginx-config-volumemountPath: /etc/nginx/conf.d/nginx.confsubPath: nginx.conf- name: my-nginx-config-volumemountPath: /etc/nginx/conf.d/my-nginx.confsubPath: my-nginx.conf

参考文档:

  1. https://stackoverflow.com/questions/65399714/what-is-the-difference-between-subpath-and-mountpath-in-kubernetes
http://www.dinnco.com/news/11309.html

相关文章:

  • 深圳西乡网站制作专业软文代写
  • 怎么用DREAMWAVER做网站识万物扫一扫
  • 类似freenom的免费域名网站天津百度推广排名优化
  • 长春网站建设外包长春seo推广
  • 苏州诗华洛网站建设网络优化工程师是干什么的
  • 手机上怎么查看网站设计计算机培训课程
  • 做公司网站解析湘潭seo优化
  • 电影资源分享网站怎么做的怎样开自己的网站
  • 深圳网站建设定制bt蚂蚁磁力搜索天堂
  • 九江建网站报价灰色行业推广平台
  • 做微信公众平台的网站刷排名seo软件
  • 网站建设要考虑哪些互联网营销是干什么
  • 国外 wordpress模板福州短视频seo网红
  • 论坛 网站建设的步骤过程上海何鹏seo
  • 做外贸必应网站产品曝光今日要闻新闻
  • 自己做网站还是挂靠好杭州seo网站优化
  • 建网站教学windows优化大师怎么彻底删除
  • 微信登录wordpress免费泉州seo托管
  • 泉州做外贸网站百度线上推广
  • 子网站建设经验汇报百度提交收录入口
  • 智慧团建官方网站提高工作效率的措施
  • 个人网站设计论文的结论建网站用什么软件
  • 网站开发运维网站单向外链推广工具
  • 张家港网站开发培训广告代理简短的软文范例
  • 三五互联做网站吗英文seo是什么意思
  • web网站开发基础jarseo关键词优化
  • 网站设置兼容模式怎么弄香港域名注册网站
  • 网站开发源代码搜索软件使用排名
  • 注册网站引流web网站设计
  • 网站建设维护人员岗位近期重大新闻事件10条