日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

k8s挂载目录_K8S中挂载目录引发的血案!

發布時間:2025/3/12 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 k8s挂载目录_K8S中挂载目录引发的血案! 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在kubernetes中部署前端項目(使用nginx作為服務器)的時候,遇到了一個報錯,報錯信息如下

2019/11/19 02:16:31 [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

提示的意思是沒有找到mine.types文件,也就是說容器內/etc/nginx下不存在這個文件。但是這個文件不是nginx提供的嗎?

我趕忙看了下我是如何部署這個容器的。

dockerfile:

FROM nginx:1.17.3

COPY dist /usr/share/nginx/html

deployment.yml:

apiVersion: apps/v1beta2

kind: Deployment

metadata:

name: smcp-web

namespace: nginx-test

spec:

selector:

matchLabels:

app: smcp-web

replicas: 1

template:

metadata:

labels:

app: smcp-web

spec:

containers:

- name: smcp-web

image: docker-registry.xxx.com/fe/fe-nginx:no-nginx-conf

ports:

- containerPort: 80

volumeMounts:

- name: nginx-conf

mountPath: /etc/nginx

volumes:

- name: nginx-conf

configMap:

name: nginx-conf

items:

- key: nginx.conf

path: nginx.conf

這樣就會將在configMap中聲明的nginx.conf對應內容掛載到/etc/nginx(mountPath)/nginx.conf文件中。

kubectl create configmap nginx-conf --from-file=nginx.conf=./path/to/nginx.conf -n nginx-test

一想到這里我大概知道了原因,是因為我們掛載的是整個/etc/nginx目錄,但是我們這個目錄里面只加了nginx.conf,而容器中/etc/nginx目錄下面還有很多其他的文件,

我們直接掛載了整個目錄進去,其他的文件會隨著目錄的掛載而消失,自然讀取配置就出了問題。

現在問題已經知道了,如何解決呢?

要是可以只掛載這個文件就好了,查閱了下文檔,發現subPath完全可以滿足我們的需求。

subPath的目的是為了在單一Pod中多次使用同一個volume而設計的

所以將spec部分修改如下:

spec:

containers:

- name: smcp-web

image: docker-registry.xxx.com/fe/fe-nginx:no-nginx-conf

ports:

- containerPort: 80

volumeMounts:

- name: nginx-conf

mountPath: /etc/nginx/nginx.conf

subPath: nginx.conf

volumes:

- name: nginx-conf

configMap:

name: nginx-conf

這樣我們就做到了將nginx.conf文件掛載到/etc/nginx目錄下,同時不影響原有目錄中的內容。

總結

以上是生活随笔為你收集整理的k8s挂载目录_K8S中挂载目录引发的血案!的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。