无法挂载自定义配置文件



我正在尝试使用Kubernetes和官方docker映像创建一个Nginx服务器。不幸的是,当我试图挂载自定义配置文件时,什么也没有发生。我的容器工作得很好,但它的默认配置文件。此外,在/etc上的另一个挂载(让加密文件夹)也不起作用。然而,certbot mount工作得很好…(如果我检查容器内/etc/nginx/nginx.conf它不是我要挂载的文件,/etc/letsencrypt不存在)我把我的部署文件链接在下面…如果有人有一个想法,想要帮助,这将是令人愉快的!

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 1 
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.19.6
ports:
- containerPort: 80
- containerPort: 443 
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
readOnly: true
volumeMounts:
- name: letsencrypt
mountPath: /etc/letsencrypt
readOnly: true
volumeMounts:
- name: certbot
mountPath: /var/www/certbot
volumes:
- name: nginx-config
nfs: 
server: 192.168.2.9
path: /volume1/nginx/nginx.conf     
- name: letsencrypt
nfs: 
server: 192.168.2.9
path: /volume1/nginx/letsencrypt
- name: certbot
nfs: 
server: 192.168.2.9
path: /volume1/nginx/certbot

编辑:为了解决这个问题,我必须将所有的卷挂载放在一个单独的volumeMount部分中,并删除卷部分中对文件的引用,如下所示:

volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
readOnly: true
- name: letsencrypt
mountPath: /etc/letsencrypt
readOnly: true
- name: certbot
mountPath: /var/www/certbot
volumes:
- name: nginx-config
nfs: 
server: 192.168.2.9
path: /volume1/nginx/    
- name: letsencrypt
nfs: 
server: 192.168.2.9
path: /volume1/nginx/letsencrypt
- name: certbot
nfs: 
server: 192.168.2.9
path: /volume1/nginx/certbot

这不起作用,因为您错误地引用了您的Volumes。不需要在Volumes挂载阶段引用文件名:

volumes:
- name: nginx-config
nfs: 
server: 192.168.2.9
path: /volume1/nginx/nginx.conf  

一旦我应用了你的配置,我的pod就处于CreateContainerConfigError状态failed to prepare subPath for volumeMount "nginx-config" of container "nginx"错误。

在这种情况下,正确的yaml应该是这样的:

volumes:
- name: nginx-config
nfs: 
server: 192.168.2.9
path: /volume1/nginx/  

我添加了一行#This is my custom config只是为了知道我的自定义文件是加载的,有结果:

➜ keti nginx-deployment-66c5547c7c-nsfzv  -- cat  /etc/nginx/nginx.conf
#This is my custom config
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
worker_connections  1024;
}
.....

我把这个答案写在社区wiki上,以便更好地了解OP解决方案,该解决方案被作为问题而不是答案的编辑。

该问题的解决方案是OP解决方案的组合,将所有卷挂载在单个volumeMount中,我的答案是删除对卷部分中文件的引用:

volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
readOnly: true
- name: letsencrypt
mountPath: /etc/letsencrypt
readOnly: true
- name: certbot
mountPath: /var/www/certbot
volumes:
- name: nginx-config
nfs: 
server: 192.168.2.9
path: /volume1/nginx/    
- name: letsencrypt
nfs: 
server: 192.168.2.9
path: /volume1/nginx/letsencrypt
- name: certbot
nfs: 
server: 192.168.2.9
path: /volume1/nginx/certbot

相关内容

  • 没有找到相关文章

最新更新